Monday, November 08, 2010 at 12:02 AM.

system.verbs.builtins.Frontier.tools.data.windowTypes.outlinerFile.saveAsHtml

on saveAsHtml (adrOutline, adrFilepath=nil, flPreview=false) { //Render an outline as HTML and save it to disk.
	<<Changes
		<<4/27/02; 9:51:38 AM by DW
			<<The flPreview flag is nutty. It's always false based on the way it's called from the kernel. Setting it true doesn't get the document to open in the browser which is what previewing should do. Further, if it's false, it opens the document in an outline window. Oy. So I changed it, so that unconditionally, the HTML rendering is displayed in the browser after you save it. Don't try turning it on, please. It's not a well-designed feature. 
		<<4/27/02; 9:30:14 AM by DW
			<<There were two references to "adr" in this script, and apparently, at one time, the address of the outline was called adr, but not any more. These two changes made Save As HTML command in the File menu work on a relatively virgin Radio 8 installation.
		<<1/30/02; 2:07:42 AM by JES
			<<Removed reference to pike.getPreferencesFolder.
		<<1/29/02; 10:39:41 PM by JES
			<<Removed references to pike.isLocalOutline and pike.titleToHtmlFileName.
		<<12/10/01; 12:33:40 AM by JES
			<<Commented out the block where a default file path was set. Not only did it reference the deprecated pike.getPreferencesFolder, but it wasn't needed in the first place. Now all we set is the default filename.
		<<12/15/00; 6:20:38 PM by PBS
			<<Call user.pike.renderOutline to create the HTML document. This script may be changed by the user to over-ride the standard behavior.
		<<12/20/00; 2:02:56 AM by JES
			<<If on a Mac, convert Mac characters to latin before writing the file to disk.
		<<12/26/00; 2:43:55 PM by PBS
			<<Works with non-file-based outlines -- gets title from window title. If local, file based outline, get it from file info table.
		<<12/13/00; 5:41:50 PM by PBS
			<<Created. Render an outline as HTML and save it to disk.
			<<adr is the address of the window to save
			<<adrFilepath is the address from which to get the file path. If adrFilepath^ == nil, it will be set to the generated file path.
			<<If flPreview is true, the file is saved in [Radio Folder]/Preferences/View in Browser/[outlineName].html.
			<<If flPreview is false, the HTML file is opened in Radio.
	
	local (f);
	if adrFilepath != nil {
		f = adrFilepath^};
	
	if f == nil { //construct a file path if not specified
		f = Frontier.tools.windowTypes.getDefaultFilename (adrOutline, user.html.prefs.fileExtension);
		local (appFolder = file.folderFromPath (Frontier.getProgramPath ()));
		local (viewInBrowserFolder = appFolder + "View in Browser" + file.getPathChar ());
		f = viewInBrowserFolder + f;
		file.sureFilePath (f)};
	
	if not flPreview { //ask the user for a path
		if not file.putFileDialog ("Save as HTML:", @f) {
			return (true)}}; //consume the command
	
	local (htmlText);
	bundle { //render the HTML
		on runUserRenderer (adrRenderer) {
			if defined (adrRenderer^) {
				local (adrScript = adrRenderer);
				try {
					while (typeOf (adrScript^) == addressType) {
						adrScript = adrScript^}};
				htmlText = adrScript^ (adrOutline);
				return (true)};
			return (false)};
		local (htmlSetByUserRenderer = false);
		if runUserRenderer (@user.tools.renderOutline) {
			htmlSetByUserRenderer = true}
		else { //legacy support for user.pike.renderOutline
			if system.environment.isRadio {
				if defined (user.pike) {
					if runUserRenderer (@user.pike.renderOutline) {
						htmlSetByUserRenderer = true}}}};
		if not htmlSetByUserRenderer { //do default rendering
			on renderOutline (adrOutline) { //from pike.renderOutline
				<<Render an outline. Return the text of the rendering.
					<<If the outline contains rules, use pikeRenderer. Otherwise do a default unordered list rendering.
					<<12/13/00; 5:03:46 PM by PBS
					<<Changes:
						<<12/26/00; 2:44:31 PM by PBS
							<<Works with non-file-based outlines -- gets title from window title. If local, file based outline, get it from file info table.
						<<12/26/00; 5:11:21 PM by PBS
							<<Add HTML 4.01 Transitional doctype declaration.
				
				local (s);
				local (adrParentTable = parentOf (adrOutline^));
				local (title = window.getTitle (adrOutline)); //PBS 12/26/00: get window title
				window.attributes.getOne ("title", @title, adrOutline); //4/27/02 by DW, change adr to adrOutline
				if string.lower (title) endsWith ".opml" {
					title = string.popSuffix (title)};
				
				local (localOutline = adrOutline^); //make a copy of the outline
				adrOutline = @localOutline;
				
				if string (adrOutline) contains "<rules>" { //rules?
					local (pt);
					new (tableType, @pt);
					html.setPageTableAddress (@pt);
					local (oldTarget = target.set (@localOutline));
					s = pikeRenderer.theRenderer (adrOutline);
					try {target.set (oldTarget)};
					s = string.replaceAll (s, "\r\r", "<p>\r");
					html.deletePageTableAddress ()}
				else { //no rules; use unordered list rendering
					s = html.getOutlineHtml (adrOutline, "\r<ul>", "\r</ul>", "\r<li>", "</li>")};
				
				bundle { //add HTML header and footer
					<<Header.
					local (headerText = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r"); //PBS 12/26/00: add DOCTYPE declaration
					headerText = headerText + "<html>\r\t<head><title>" + title + "</title></head>\r";
					headerText = headerText + "\t<body bgcolor=\"white\">\r";
					
					<<HTML title.
					headerText = headerText + "<h2>" + title + "</h2>\r";
					
					s = headerText + s;
					
					<<Footer.
					local (footerText = "\r\t\t</body>\r\t</html>");
					
					s = s + footerText};
				
				bundle { //if this is a PC, add line feeds
					if system.environment.isWindows {
						s = string.replaceAll (s, "\r", "\r\n")}};
				
				return (s)};
			htmlText = renderOutline (adrOutline)}}; //4/27/02 by DW, change adr to adrOutline
	
	if system.environment.isMac { //12/20/00 JES: if on a Mac, convert Mac characters to latin
		htmlText = latinToMac.macToLatin (htmlText)};
	file.writeWholeFile (f, htmlText, 'TEXT', user.html.prefs.textFileCreator, clock.now ());
	
	if adrFilepath != nil { //tell the caller where the file is -- used for View in Browser
		adrFilepath^ = f};
	
	bundle { //4/27/02 by DW, see comment at head of script
		<<if not flPreview
			<<return (Frontier.tools.windowTypes.commands.open (f))
		webbrowser.opendocument (f)};
	return (true)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.