00e99f1d2952617e192496a96d50b5d6e5fbe3b9
5 * Parses for text marked as a code example block.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Code.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
21 * Parses for text marked as a code example block.
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.
34 * @author Paul M. Jones <pmjones@php.net>
38 class Text_Wiki_Parse_Code
extends Text_Wiki_Parse
{
43 * The regular expression used to find source text matching this
52 var $regex = '/^(\<code( .+)?\>)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';
57 * Generates a token entry for the matched text. Token options are:
59 * 'text' => The full matched text, not including the <code></code> tags.
63 * @param array &$matches The array of matches from parse().
65 * @return A delimited token number to be used as a placeholder in
70 function process(&$matches)
72 // are there additional attribute arguments?
73 $args = trim($matches[2]);
77 'text' => $matches[3],
78 'attr' => array('type' => '')
81 // get the attributes...
82 $attr = $this->getAttrs($args);
84 // ... and make sure we have a 'type'
85 if (! isset($attr['type'])) {
91 'text' => $matches[3],
96 return $this->wiki
->addToken($this->rule
, $options) . $matches[5];