[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/Text/Wiki/Rule/ -> deflist.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4: */
   3  // +----------------------------------------------------------------------+
   4  // | PHP version 4                                                        |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997-2003 The PHP Group                                |
   7  // +----------------------------------------------------------------------+
   8  // | This source file is subject to version 2.0 of the PHP license,       |
   9  // | that is bundled with this package in the file LICENSE, and is        |
  10  // | available through the world-wide-web at                              |
  11  // | http://www.php.net/license/2_02.txt.                                 |
  12  // | If you did not receive a copy of the PHP license and are unable to   |
  13  // | obtain it through the world-wide-web, please send a note to          |
  14  // | license@php.net so we can mail you a copy immediately.               |
  15  // +----------------------------------------------------------------------+
  16  // | Authors: Paul M. Jones <pmjones@ciaweb.net>                          |
  17  // +----------------------------------------------------------------------+
  18  //
  19  // $Id: deflist.php,v 1.3 2004/12/02 10:54:32 nohn Exp $
  20  
  21  
  22  /**
  23  * 
  24  * This class implements a Text_Wiki_Rule to find source text marked as a
  25  * definition list.  In short, if a line starts with ':' then it is a
  26  * definition list item; another ':' on the same lines indicates the end
  27  * of the definition term and the beginning of the definition narrative.
  28  * The list items must be on sequential lines (no blank lines between
  29  * them) -- a blank line indicates the beginning of a new list.
  30  *
  31  * @author Paul M. Jones <pmjones@ciaweb.net>
  32  *
  33  * @package Text_Wiki
  34  *
  35  */
  36  
  37  class Text_Wiki_Rule_deflist extends Text_Wiki_Rule {
  38      
  39      
  40      /**
  41      * 
  42      * The regular expression used to parse the source text and find
  43      * matches conforming to this rule.  Used by the parse() method.
  44      * 
  45      * @access public
  46      * 
  47      * @var string
  48      * 
  49      * @see parse()
  50      * 
  51      */
  52      
  53      var $regex = '/\n((:).*\n)(?!(:))/Us';
  54      
  55      
  56      /**
  57      * 
  58      * Generates a replacement for the matched text.  Token options are:
  59      * 
  60      * 'type' =>
  61      *     'list_start'    : the start of a definition list
  62      *     'list_end'      : the end of a definition list
  63      *     'term_start'    : the start of a definition term
  64      *     'term_end'      : the end of a definition term
  65      *     'narr_start'    : the start of definition narrative
  66      *     'narr_end'      : the end of definition narrative
  67      *     'unknown'       : unknown type of definition portion
  68      *
  69      * @access public
  70      *
  71      * @param array &$matches The array of matches from parse().
  72      *
  73      * @return A series of text and delimited tokens marking the different
  74      * list text and list elements.
  75      *
  76      */
  77      
  78      function process(&$matches)
  79      {
  80          // the replacement text we will return to parse()
  81          $return = '';
  82          
  83          // the list of post-processing matches
  84          $list = array();
  85          
  86          // start the deflist
  87          $options = array('type' => 'list_start');
  88          $return .= $this->addToken($options);
  89          
  90          // $matches[1] is the text matched as a list set by parse();
  91          // create an array called $list that contains a new set of
  92          // matches for the various definition-list elements.
  93          preg_match_all(
  94              '/^(:)(.*)?(:)(.*)?$/Ums',
  95              $matches[1],
  96              $list,
  97              PREG_SET_ORDER
  98          );
  99          
 100          // add each term and narrative
 101          foreach ($list as $key => $val) {
 102              $return .= (
 103                  $this->addToken(array('type' => 'term_start')) .
 104                  trim($val[2]) .
 105                  $this->addToken(array('type' => 'term_end')) .
 106                  $this->addToken(array('type' => 'narr_start')) .
 107                  trim($val[4]) . 
 108                  $this->addToken(array('type' => 'narr_end'))
 109              );
 110          }
 111          
 112          
 113          // end the deflist
 114          $options = array('type' => 'list_end');
 115          $return .= $this->addToken($options);
 116          
 117          // done!
 118          return "\n" . $return . "\n";
 119      }
 120      
 121      
 122      /**
 123      * 
 124      * Renders a token into text matching the requested format.
 125      * 
 126      * @access public
 127      * 
 128      * @param array $options The "options" portion of the token (second
 129      * element).
 130      * 
 131      * @return string The text rendered from the token options.
 132      * 
 133      */
 134      
 135      function renderXhtml($options)
 136      {
 137          $type = $options['type'];
 138          $pad = "    ";
 139          
 140          switch ($type) {
 141          
 142          case 'list_start':
 143              return "<dl>\n";
 144              break;
 145          
 146          case 'list_end':
 147              return "</dl>\n";
 148              break;
 149          
 150          case 'term_start':
 151              return $pad . "<dt>";
 152              break;
 153          
 154          case 'term_end':
 155              return "</dt>\n";
 156              break;
 157          
 158          case 'narr_start':
 159              return $pad . $pad . "<dd>";
 160              break;
 161          
 162          case 'narr_end':
 163              return "</dd>\n";
 164              break;
 165          
 166          default:
 167              return '';
 168          
 169          }
 170      }
 171  }
 172  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics