                                                                                                                                                                                                                                                                    


<?php
//-->-->-->-->-->-->-->-->
//-- Description:
//--   The purpose of this function is to perform common HTML transforms
//--   on a plain text document. In this case the word common refers
//--   to the fact that the transformations are shared among a number
//--   of files, not that they are very frequent or usual.
//--    
//--
//-- Notes:
//--
//--
//-- Dependencies:
//--
//-- See Also:
//-- 
//--   fnMessageToHtml
//--   fnHyperlinkPlainText
//--   fnReduplicateCharacters
//--   fnUnduplicateCharacters
//--   fnCodeBlockToHtml
//--   fnCodeBlockFromHtml
//--   fnListBlockToHtml
//--   retrovox-notepad-save.php    
//--   retrovox-notepad.php    
//--     A script to allow editing of files located on a server using a web
//--     browser.
//--
//-- Author:
//--   matth3wbishop@yahoo.com
//--   http://www.geocities.com/matth3wbishop/
//--

function fnHtmlCommonTransforms($sPlainText)
{
  $sReturn = $sPlainText;

  //-- On lines that have nothing but spaces, delete the spaces
  //$sReturn = preg_replace("#\n\s*\n#im", "\n\n", $sReturn);

  //-- The special tag [*document*] is used by the editor of the 
  //-- document to indicate that this document should be interpreted
  //-- as a 'document'. Is that confusing enough for you. I am using
  //-- the word document to mean a text file which has section headings
  $sReturn = preg_replace("#^\s*\[\*document\*\]\s*$#im", "\n\n", $sReturn);
  //-- The CWC is used by community work centre pages
  $sReturn = preg_replace("#^\s*\[\*cwc\*\]\s*$#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);




  //-- Trailing space serves no purpose.
  $sReturn = preg_replace("#[ \t]*([\n\r])#m", "$1", $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("--&lt;&lt;", "</pre>", $sReturn);

  $sReturn = str_replace("--&gt;&gt;", "<pre>", $sReturn);
  $sReturn = 
    preg_replace(
         "#<pre>((.|\n)*?)</pre>#ime", 
         "'<pre>'.fnCodeBlockToHtml('$1').'</pre>'", $sReturn);
  

  $sReturn = 
    preg_replace(
         "#^\s*([a1Iu]-(.|\n)*?)\n\s*\n#ime", 
         "''.fnListBlockToHtml('$1').'\n\n'", $sReturn);


  //-- Make empty lines delimite HTML paragraphs
  $sReturn = preg_replace("#^\s*$#im", "</p><p>", $sReturn);

  //-- Make the title into a first level heading  
  $sReturn = 
    preg_replace("#^[ ]*=(.*)#m", "<center><h1>$1</h1></center><dl>", $sReturn);

  //-- Emphasize 'notes' and 'warnings' 
  $sReturn = 
    preg_replace("#(please note|note|warning):#im", 
                 "<em>$1:</em>", $sReturn);

  //-- Make key reference into fake html buttons
  $sReturn = 
    preg_replace("#(the\s{1,4}escape\s{1,4}key\s{1,4})#im", 
                 "the <form><button value = 'ESC'></form> key", $sReturn);


  return $sReturn;
} //-- function fnHtmlCommonTransforms 
     

//--<--<--<--<--<--<--<--<
?>
                                                                                                                                                                                                                                                                                                    