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

system.verbs.builtins.html.loadTextFile

on loadTextFile (f, adrsite) {
	on cleanup (s) { <<common text cleanup ops
		s = string.replaceall (s, "\n", "");
		s = string.replaceall (s, """, "\"");
		s = string.replaceall (s, "&", "&");
		
		bundle { <<frontpage 2.0 uses lowercase Ps in <p> tags
			s = string.replaceall (s, "<p>#", "#");
			s = string.replaceall (s, "<p>", "");
			s = string.replaceall (s, "</p>", "")};
		bundle { <<pagemill 2.0 uses uppercase Ps in <p> tags
			s = string.replaceall (s, "<P>#", "#");
			s = string.replaceall (s, "<P>", "");
			s = string.replaceall (s, "</P>", "")};
		s = string.popleading (s, '\r');
		return (s)};
	on loadpage (s) {
		local (pageName = html.normalizeName (string.popSuffix (file.fileFromPath (f))));
		local (adrPage = @adrsite^.[pageName]);
		wp.newTextObject (cleanup (s), adrPage);
		return (adrPage)};
	
	<<Wednesday, January 14, 1998 at 12:10:14 PM by PBS
		<<If it's a gif or a jpeg, call html.loadImageFile.
		<<Otherwise, load as text.
	local (filetype = file.type (f));
	filetype = string.lower (string.poptrailing (filetype, ' '));
	case filetype {
		"gif";
		"giff";
		"jpg";
		"jpeg" {
			return (html.loadImageFile (f, adrsite))}};
	
	<<Look for a text driver that wants to handle this file.
		<<If one is not found, load the file unmodified as text.
	local (adrdrivers = @html.data.textFileReaders, i);
	for i = 1 to sizeof (adrdrivers^) {
		local (adrscript = @adrdrivers^ [i], pageinfo);
		new (tabletype, @pageinfo);
		if adrscript^ (f, @pageinfo) { <<the driver accepted the file
			return (loadpage (pageinfo.pagetext))}};
	
	<<No driver found. Default is to load as unmodified text.
	return (loadpage (string (file.readWholeFile (f))))}



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.