[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/Text/Wiki/Rule/ -> paragraph.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: paragraph.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 sections of the source
  25  * text that are paragraphs.  A para is any line not starting with a token
  26  * delimiter, followed by two newlines.
  27  *
  28  * @author Paul M. Jones <pmjones@ciaweb.net>
  29  *
  30  * @package Text_Wiki
  31  *
  32  */
  33  
  34  class Text_Wiki_Rule_paragraph extends Text_Wiki_Rule {
  35      
  36      /**
  37      * 
  38      * The regular expression used to find source text matching this
  39      * rule.
  40      * 
  41      * @access public
  42      * 
  43      * @var string
  44      * 
  45      */
  46      
  47      var $regex = "/^.*?\n\n/m";
  48      
  49      
  50      /**
  51      * 
  52      * Generates a token entry for the matched text.  Token options are:
  53      * 
  54      * 'start' => The starting point of the paragraph.
  55      * 
  56      * 'end' => The endinging point of the paragraph.
  57      * 
  58      * @access public
  59      *
  60      * @param array &$matches The array of matches from parse().
  61      *
  62      * @return A delimited token number to be used as a placeholder in
  63      * the source text.
  64      *
  65      */
  66      
  67      function process(&$matches)
  68      {
  69          $delim = $this->_wiki->delim;
  70          
  71          // was anything there?
  72          if (trim($matches[0]) == '') {
  73              return '';
  74          }
  75          
  76          // does the match start with a delimiter?
  77          if (substr($matches[0], 0, 1) != $delim) { 
  78              // no.
  79              $start = $this->addToken(array('type' => 'start'));
  80              $end = $this->addToken(array('type' => 'end'));
  81              return $start . trim($matches[0]) . $end;
  82          }
  83          
  84          // the line starts with a delimiter.  read in the delimited
  85          // token number, check the token, and see if we should
  86          // skip it.
  87          
  88          // loop starting at the second character (we already know
  89          // the first is a delimiter) until we find another
  90          // delimiter; the text between them is a token key number.
  91          $key = '';
  92          $len = strlen($matches[0]);
  93          for ($i = 1; $i < $len; $i++) {
  94              $char = $matches[0]{$i};
  95              if ($char == $delim) {
  96                  break;
  97              } else {
  98                  $key .= $char;
  99              }
 100          }
 101          
 102          // look at the token and see if it's skippable (if we skip,
 103          // it will not be marked as a paragraph)
 104          $token_type = $this->_wiki->_tokens[$key][0];
 105          if (in_array($token_type, $this->_conf['skip'])) {
 106              return $matches[0];
 107          } else {
 108              $start = $this->addToken(array('type' => 'start'));
 109              $end = $this->addToken(array('type' => 'end'));
 110              return $start . trim($matches[0]) . $end;
 111          }
 112      }
 113      
 114      
 115      /**
 116      * 
 117      * Renders a token into text matching the requested format.
 118      * 
 119      * @access public
 120      * 
 121      * @param array $options The "options" portion of the token (second
 122      * element).
 123      * 
 124      * @return string The text rendered from the token options.
 125      * 
 126      */
 127      
 128      function renderXhtml($options)
 129      {
 130          extract($options); //type
 131          
 132          if ($type == 'start') {
 133              return '<p>';
 134          }
 135          
 136          if ($type == 'end') {
 137              return "</p>\n\n";
 138          }
 139      }
 140  }
 141  ?>


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