includes/wikiengine/Parse/Default/Code.php
changeset 1027 98c052fc3337
parent 1026 f0431eb8161e
child 1028 dde4416dea00
equal deleted inserted replaced
1026:f0431eb8161e 1027:98c052fc3337
     1 <?php
       
     2 
       
     3 /**
       
     4 * 
       
     5 * Parses for text marked as a code example block.
       
     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: Code.php,v 1.10 2006/02/21 14:33:53 toggg Exp $
       
    16 * 
       
    17 */
       
    18 
       
    19 /**
       
    20 * 
       
    21 * Parses for text marked as a code example block.
       
    22 * 
       
    23 * This class implements a Text_Wiki_Parse to find sections marked as code
       
    24 * examples.  Blocks are marked as the string <code> on a line by itself,
       
    25 * followed by the inline code example, and terminated with the string
       
    26 * </code> on a line by itself.  The code example is run through the
       
    27 * native PHP highlight_string() function to colorize it, then surrounded
       
    28 * with <pre>...</pre> tags when rendered as XHTML.
       
    29 *
       
    30 * @category Text
       
    31 * 
       
    32 * @package Text_Wiki
       
    33 * 
       
    34 * @author Paul M. Jones <pmjones@php.net>
       
    35 * 
       
    36 */
       
    37 
       
    38 class Text_Wiki_Parse_Code extends Text_Wiki_Parse {
       
    39     
       
    40     
       
    41     /**
       
    42     * 
       
    43     * The regular expression used to find source text matching this
       
    44     * rule.
       
    45     * 
       
    46     * @access public
       
    47     * 
       
    48     * @var string
       
    49     * 
       
    50     */
       
    51     
       
    52 /*    var $regex = '/^(\<code( .+)?\>)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';*/
       
    53     var $regex = ';^<code(\s[^>]*)?>((?:(?R)|.)*?)\n</code>(\s|$);msi';
       
    54     
       
    55     /**
       
    56     * 
       
    57     * Generates a token entry for the matched text.  Token options are:
       
    58     * 
       
    59     * 'text' => The full matched text, not including the <code></code> tags.
       
    60     * 
       
    61     * @access public
       
    62     *
       
    63     * @param array &$matches The array of matches from parse().
       
    64     *
       
    65     * @return A delimited token number to be used as a placeholder in
       
    66     * the source text.
       
    67     *
       
    68     */
       
    69     
       
    70     function process(&$matches)
       
    71     {
       
    72         // are there additional attribute arguments?
       
    73         $args = trim($matches[1]);
       
    74         
       
    75         if ($args == '') {
       
    76             $options = array(
       
    77                 'text' => $matches[2],
       
    78                 'attr' => array('type' => '')
       
    79             );
       
    80         } else {
       
    81         	// get the attributes...
       
    82         	$attr = $this->getAttrs($args);
       
    83         	
       
    84         	// ... and make sure we have a 'type'
       
    85         	if (! isset($attr['type'])) {
       
    86         		$attr['type'] = '';
       
    87         	}
       
    88         	
       
    89         	// retain the options
       
    90             $options = array(
       
    91                 'text' => $matches[2],
       
    92                 'attr' => $attr
       
    93             );
       
    94         }
       
    95         
       
    96         return $this->wiki->addToken($this->rule, $options) . $matches[3];
       
    97     }
       
    98 }
       
    99 ?>