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

Source for file Blockquote.php

Documentation is available at Blockquote.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * Parse for block-quoted text.
  6.  *
  7.  * Find source text marked as a blockquote, identified by any number of
  8.  * greater-than signs '>' at the start of the line, followed by an
  9.  * optional space, and then the quote text; each '>' indicates an
  10.  * additional level of quoting.
  11.  *
  12.  * @category Text
  13.  *
  14.  * @package Text_Wiki
  15.  *
  16.  * @author Paul M. Jones <pmjones@php.net>
  17.  * @author Michele Tomaiuolo <tomamic@yahoo.it>
  18.  *
  19.  * @license LGPL
  20.  *
  21.  * @version $Id: Blockquote.php 230214 2007-02-19 08:57:14Z mic $
  22.  *
  23.  */
  24.  
  25. class Text_Wiki_Parse_Blockquote extends Text_Wiki_Parse {
  26.  
  27.  
  28.     /**
  29.     *
  30.     * Regex for parsing the source text.
  31.     *
  32.     * @access public
  33.     *
  34.     * @var string 
  35.     *
  36.     * @see parse()
  37.     *
  38.     */
  39.  
  40.     var $regex = '/\n(([>:]).*\n)(?!([>:]))/Us';
  41.  
  42.  
  43.     /**
  44.     *
  45.     * Generates a replacement for the matched text.
  46.     *
  47.     * Token options are:
  48.     *
  49.     * 'type' =>
  50.     *     'start' : the start of a blockquote
  51.     *     'end'   : the end of a blockquote
  52.     *
  53.     * 'level' => the indent level (0 for the first level, 1 for the
  54.     * second, etc)
  55.     *
  56.     * @access public
  57.     *
  58.     * @param array &$matches The array of matches from parse().
  59.     *
  60.     * @return series of text and delimited tokens marking the different
  61.     *  list text and list elements.
  62.     *
  63.     */
  64.  
  65.     function process(&$matches)
  66.     {
  67.         // the replacement text we will return to parse()
  68.         $return '';
  69.  
  70.         // the list of post-processing matches
  71.         $list = array();
  72.  
  73.         // $matches[1] is the text matched as a list set by parse();
  74.         // create an array called $list that contains a new set of
  75.         // matches for the various list-item elements.
  76.         preg_match_all(
  77.             '=^([>:]+)(.*?\n)=ms',
  78.             $matches[1],
  79.             $list,
  80.             PREG_SET_ORDER
  81.         );
  82.  
  83.         // a stack of starts and ends; we keep this so that we know what
  84.         // indent level we're at.
  85.         $stack = array();
  86.  
  87.         // loop through each list-item element.
  88.         foreach ($list as $key => $val{
  89.  
  90.             // $val[0] is the full matched list-item line
  91.             // $val[1] is the number of initial '>' chars (indent level)
  92.             // $val[2] is the quote text
  93.  
  94.             // we number levels starting at 1, not zero
  95.             $level strlen($val[1]);
  96.  
  97.             // get the text of the line
  98.             $text trim($val[2]);
  99.  
  100.             // add a level to the list?
  101.             while ($level count($stack)) {
  102.                 
  103.                 $css ($val[1][count($stack)== ':''remark' '';
  104.                 
  105.                 // the current indent level is greater than the number
  106.                 // of stack elements, so we must be starting a new
  107.                 // level.  push the new level onto the stack with a
  108.                 // dummy value (boolean true)...
  109.                 array_push($stacktrue);
  110.  
  111.                 $return .= "\n\n";
  112.  
  113.                 // ...and add a start token to the return.
  114.                 $return .= $this->wiki->addToken(
  115.                     $this->rule,
  116.                     array(
  117.                         'type' => 'start',
  118.                         'level' => $level - 1,
  119.                         'css' => $css
  120.                     )
  121.                 );
  122.  
  123.                 $return .= "\n\n";
  124.             }
  125.  
  126.             // remove a level?
  127.             while (count($stack$level{
  128.  
  129.                 // as long as the stack count is greater than the
  130.                 // current indent level, we need to end list types.
  131.                 // continue adding end-list tokens until the stack count
  132.                 // and the indent level are the same.
  133.                 array_pop($stack);
  134.  
  135.                 $return .= "\n\n";
  136.  
  137.                 $return .= $this->wiki->addToken(
  138.                     $this->rule,
  139.                     array (
  140.                         'type' => 'end',
  141.                         'level' => count($stack)
  142.                     )
  143.                 );
  144.  
  145.                 $return .= "\n\n";
  146.             }
  147.  
  148.             // add the line text.
  149.             $return .= $text "\n";
  150.         }
  151.  
  152.         // the last line may have been indented.  go through the stack
  153.         // and create end-tokens until the stack is empty.
  154.         $return .= "\n\n";
  155.  
  156.         while (count($stack> 0{
  157.             array_pop($stack);
  158.  
  159.             $return .= "\n\n";
  160.  
  161.             $return .= $this->wiki->addToken(
  162.                 $this->rule,
  163.                 array (
  164.                     'type' => 'end',
  165.                     'level' => count($stack)
  166.                 )
  167.             );
  168.  
  169.             $return .= "\n\n";
  170.         }
  171.  
  172.         // we're done!  send back the replacement text.
  173.         return "\n\n$return\n\n";
  174.     }
  175. }
  176. ?>

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