Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Trim.php

Documentation is available at Trim.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * Trim lines in the source text and compress 3 or more newlines to
  6.  * 2 newlines.
  7.  *
  8.  * @category Text
  9.  *
  10.  * @package Text_Wiki
  11.  *
  12.  * @author Paul M. Jones <pmjones@php.net>
  13.  * @author Michele Tomaiuolo <tomamic@yahoo.it>
  14.  *
  15.  */
  16.  
  17. class Text_Wiki_Parse_Trim extends Text_Wiki_Parse {
  18.  
  19.  
  20.     /**
  21.      *
  22.      * Simple parsing method.
  23.      *
  24.      * @access public
  25.      *
  26.      */
  27.  
  28.     function parse()
  29.     {
  30.         // trim lines
  31.         $find "/ *\n */";
  32.         $replace "\n";
  33.         $this->wiki->source = preg_replace($find$replace$this->wiki->source);
  34.  
  35.         // trim lines with only one dash or star
  36.         $find "/\n[\-\*]\n/";
  37.         $replace "\n\n";
  38.         $this->wiki->source = preg_replace($find$replace$this->wiki->source);
  39.  
  40.         // finally, compress all instances of 3 or more newlines
  41.         // down to two newlines.
  42.         $find "/\n{3,}/m";
  43.         $replace "\n\n";
  44.         $this->wiki->source = preg_replace($find$replace$this->wiki->source);
  45.             
  46.         // numbered lists
  47.         $find "/(\n[\*\#]*)([\d]+[\.\)]|[\w]\)) /s";
  48.         $replace "$1# ";
  49.         $this->wiki->source = preg_replace($find$replace$this->wiki->source);
  50.  
  51.         // numbers in parentesis are footnotes and references
  52.         $find "/\(([\d][\d]?)\)/";
  53.         $replace "[$1]";
  54.         $this->wiki->source = preg_replace($find$replace$this->wiki->source);
  55.  
  56.         // add hr before footnotes
  57.         $find "/(\n+\-\-\-\-+\n*)?(\n\[[\d]+\].*)/s";
  58.         $replace "\n\n----\n\n$2";
  59.         $this->wiki->source = preg_replace($find$replace$this->wiki->source);
  60.  
  61.         /*
  62.         // wrap images in tables
  63.         $find = "/(?<=\n\n){{([^\|}]*)\|([^}]*)}}(?=\n\n)/";
  64.         $replace = "| {{ $1 | $2 }}\n|= $2";
  65.         $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
  66.         
  67.         // wrap images in tables
  68.         $find = "/(?<=\n\n){{([^\|}]*)}}(?=\n\n)/";
  69.         $replace = "| {{ $1 }}";
  70.         $this->wiki->source = preg_replace($find, $replace, $this->wiki->source);
  71.         */
  72.     }
  73.  
  74. }
  75. ?>

Documentation generated on Mon, 11 Mar 2019 15:40:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.