<?php //-->-->-->-->-->-->-->--> //-- Description: //-- The purpose of this function is to transform a journal or diary //-- into some kind of meaningful HTML. The plain text is expected to //-- have as little 'mark-up' imbedded within it as is possible for //-- the given application. This attempt is an evolution on previous //-- efforts which I have written which were written in the Unix Bash //-- shell scripting language and which relied heavily programs such //-- as 'sed' and 'grep'. //-- //-- These previous efforts should be viewable at URL's such as //-- http://www.geocities.com/matth3wbishop/ and (if it still exists) //-- http://www.ella-associates.org/alexis-docs/ //-- //-- The overall purpose of this effort is to attempt to allow an //-- author to write texts in a plain text editor such as //-- Microsoft Notepad or Vi or Vim or Emacs or Nano etc and for those //-- written texts to be transformed into readable and function HTML //-- and even possibly DocBook XML. //-- //-- Please see the file //-- fnHyperlinkPlainText.php for explanations as to what sort of //-- plain text structures will be hyperlinked. //-- //-- Dependencies: //-- fnHyperlinkPlainText //-- fnReduplicateCharacters //-- fnUnduplicateCharacters //-- //--
function fnJournalToHtml($sPlainText) { $sReturn = $sPlainText;
//-- On lines that have nothing but spaces, delete the spaces //$sReturn = preg_replace("#\n\s*\n#im", "\n\n", $sReturn);
//-- Entitize special HTML characters such as < and > so that these //-- characters will not be considered part of the resulting HTML. //-- We have to do this first so that the HTML which we later insert //-- (such as hyperlinks) does not also get entitized. I //-- might also have to entitize accented characters such as ??? $sReturn = htmlspecialchars($sReturn);
//-- Make empty lines delimite HTML paragraphs $sReturn = preg_replace("#^\s*$#im", "</p><p>", $sReturn);
//-- Trailing space serves no purpose. $sReturn = preg_replace("#\s*\n#im", "\n", $sReturn);
//-- Try to allow the delimiters and to stop any further //-- transformations on the plain text (by placing the text with HTML //-- <pre> tags and then doubling every letter $sReturn = str_replace("--<<", "</pre>", $sReturn);
$sReturn = str_replace("-->>", "<pre>", $sReturn);
//-- Make the title into a first level heading $sReturn = preg_replace("#^[ ]*=(.*)#m", "<center><h1>$1</h1></center><dl>", $sReturn);
//-- Section headings are lines that are in upper case but these lines //-- can also contain punctuation. So the test below is that the lines do NOT //-- contain lower case letters. $sHeadings = preg_replace('#^\s*[^\*].*$#m', '', $sReturn);
$sHeadings = preg_replace("#\n\s*\n#m", "\n", $sHeadings);
//-- Get rid of the leading 'star' characters for each of the journal entries $sHeadings = preg_replace("#^\s*\*\s*#m", "", $sHeadings);
$sHeadings = preg_replace("#\s*$#m", "", $sHeadings);
$sHeadings = preg_replace("#^(.*)$#m", "<a href = '#$1'>$1</a> | " , $sHeadings);
$sHeadings = "<a name = 'toc'></a><br><center>".$sHeadings."</center>";
//echo "<pre>[$sHeadings]</pre>"; //echo $sHeadings; $sReturn = preg_replace( "#^\s*\*\s*(.*)$#m", "<dt><strong><a name = '$1'>$1</a></strong> <a href = '#toc'>[toc]</a></dt><dd>", $sReturn);
$sReturn = $sHeadings."\n".$sReturn;
$sReturn = fnHyperlinkPlainText($sReturn);
//-- Turn line breaks into <br> tags. This isn't really a good idea //-- since you dont know the width of the target screen // $sReturn = preg_replace("#\n#im", "\n<br>", $sReturn);
//-- Make a tab into 2 HTML spaces $sReturn = preg_replace("#\t#im", " ", $sReturn);
//-- transform spaces into entitized HTML //$sReturn = preg_replace("#\s\s#im", " ", $sReturn);
//-- Delete pre tags since line breaks and spaces are being put //-- in anyway $sReturn = preg_replace("#</?pre>#im", "", $sReturn);
//-- get rid of the meta-tag which is used to tell the transformation //-- system that the current document should be transformed according to the //-- rules for a journal or diary style document. $sReturn = preg_replace("#\[\*journal\*\]#im", "</dl>", $sReturn);
return $sReturn; } //-- function fnJournalToHtml
//--<--<--<--<--<--<--<--< ?>