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

Source for file code.php

Documentation is available at code.php

  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: code.php,v 1.2 2004/01/04 16:03:24 pmjones Exp $
  20.  
  21.  
  22. /**
  23. * This class implements a Text_Wiki_Rule 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. @author Paul M. Jones <pmjones@ciaweb.net>
  31. *
  32. @package Text_Wiki
  33. *
  34. */
  35.  
  36.     
  37.     
  38.     /**
  39.     * 
  40.     * The regular expression used to find source text matching this
  41.     * rule.
  42.     * 
  43.     * @access public
  44.     * 
  45.     * @var string 
  46.     * 
  47.     */
  48.     
  49.     var $regex = '/^(\<code\>)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';
  50.     
  51.     
  52.     /**
  53.     * 
  54.     * Generates a token entry for the matched text.  Token options are:
  55.     * 
  56.     * 'text' => The full matched text, not including the <code></code> tags.
  57.     * 
  58.     * @access public
  59.     *
  60.     * @param array &$matches The array of matches from parse().
  61.     *
  62.     * @return delimited token number to be used as a placeholder in
  63.     *  the source text.
  64.     *
  65.     */
  66.     
  67.     function process(&$matches)
  68.     {
  69.         $options = array('text' => $matches[2]);
  70.         return $this->addToken($options$matches[4];
  71.     }
  72.     
  73.     
  74.     /**
  75.     * 
  76.     * Renders a token into text matching the requested format.
  77.     * 
  78.     * @access public
  79.     * 
  80.     * @param array $options The "options" portion of the token (second
  81.     *  element).
  82.     * 
  83.     * @return string The text rendered from the token options.
  84.     * 
  85.     */
  86.     
  87.     function renderXhtml($options)
  88.     {
  89.         // trim opening and closing whitespace
  90.         $text trim($options['text']);
  91.         
  92.         // convert tabs to four spaces
  93.         $text str_replace("\t""    "$text);
  94.         
  95.         // convert entities
  96.         $text htmlentities($text);
  97.         
  98.         // done!
  99.         return "\n<pre><code>$text</code></pre>\n";
  100.     }
  101. }
  102. ?>

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