includes/wikiengine/Parse/Default/Prefilter.php
changeset 1 fe660c52c48f
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 <?php
       
     2 
       
     3 /**
       
     4 * 
       
     5 * "Pre-filter" the source text.
       
     6 * 
       
     7 * @category Text
       
     8 * 
       
     9 * @package Text_Wiki
       
    10 * 
       
    11 * @author Paul M. Jones <pmjones@php.net>
       
    12 * 
       
    13 * @license LGPL
       
    14 * 
       
    15 * @version $Id: Prefilter.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
       
    16 * 
       
    17 */
       
    18 
       
    19 /**
       
    20 * 
       
    21 * "Pre-filter" the source text.
       
    22 * 
       
    23 * Convert DOS and Mac line endings to Unix, concat lines ending in a
       
    24 * backslash \ with the next line, convert tabs to 4-spaces, add newlines
       
    25 * to the top and end of the source text, compress 3 or more newlines to
       
    26 * 2 newlines.
       
    27 *
       
    28 * @category Text
       
    29 * 
       
    30 * @package Text_Wiki
       
    31 * 
       
    32 * @author Paul M. Jones <pmjones@php.net>
       
    33 * 
       
    34 */
       
    35 
       
    36 class Text_Wiki_Parse_Prefilter extends Text_Wiki_Parse {
       
    37     
       
    38     
       
    39     /**
       
    40     * 
       
    41     * Simple parsing method.
       
    42     *
       
    43     * @access public
       
    44     * 
       
    45     */
       
    46     
       
    47     function parse()
       
    48     {
       
    49         // convert DOS line endings
       
    50         $this->wiki->source = str_replace("\r\n", "\n",
       
    51             $this->wiki->source);
       
    52         
       
    53         // convert Macintosh line endings
       
    54         $this->wiki->source = str_replace("\r", "\n",
       
    55             $this->wiki->source);
       
    56         
       
    57         // concat lines ending in a backslash
       
    58         $this->wiki->source = str_replace("\\\n", "",
       
    59             $this->wiki->source);
       
    60         
       
    61         // convert tabs to four-spaces
       
    62         $this->wiki->source = str_replace("\t", "    ",
       
    63             $this->wiki->source);
       
    64            
       
    65         // add extra newlines at the top and end; this
       
    66         // seems to help many rules.
       
    67         $this->wiki->source = "\n" . $this->wiki->source . "\n\n";
       
    68         
       
    69         // finally, compress all instances of 3 or more newlines
       
    70         // down to two newlines.
       
    71         $find = "/\n{3,}/m";
       
    72         $replace = "\n\n";
       
    73         $this->wiki->source = preg_replace($find, $replace,
       
    74             $this->wiki->source);
       
    75     }
       
    76 
       
    77 }
       
    78 ?>