1<?php
2// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
3/**
4 * BBCode: Parses for code blocks.
5 *
6 * This class implements a Text_Wiki_Rule to find source text marked as
7 * code blocks as defined by text surrounded by [code] ... [/code]
8 * On parsing, the text itself is left in place, but the starting and ending
9 * tags are replaced with tokens. (nested blocks ignored)
10 *
11 * PHP versions 4 and 5
12 *
13 * @category   Text
14 * @package    Text_Wiki
15 * @author     Bertrand Gugger <bertrand@toggg.com>
16 * @copyright  2005 bertrand Gugger
17 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
18 * @version    CVS: $Id$
19 * @link       http://pear.php.net/package/Text_Wiki
20 */
21
22/**
23 * Code block rule parser class for BBCode.
24 *
25 * @category   Text
26 * @package    Text_Wiki
27 * @author     Bertrand Gugger <bertrand@toggg.com>
28 * @copyright  2005 bertrand Gugger
29 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
30 * @version    Release: @package_version@
31 * @link       http://pear.php.net/package/Text_Wiki
32 * @see        Text_Wiki_Parse::Text_Wiki_Parse()
33 */
34class Text_Wiki_Parse_Code extends Text_Wiki_Parse {
35
36    /**
37     * The regular expression used to parse the source text and find
38     * matches conforming to this rule.  Used by the parse() method.
39     *
40     * @access public
41     * @var string
42     * @see parse()
43     */
44    var $regex =  "#\[code]((?:(?R)|.)*?)\[/code]#msi";
45
46
47    /**
48     * Generates a replacement for the matched text.  Token options are:
49     * - 'text' => the contained text
50     * - 'attr' => type empty
51     *
52     * @param array &$matches The array of matches from parse().
53     * @return A delimited token to be used as a placeholder in
54     * the source text and containing the original block of text
55     * @access public
56     */
57    function process(&$matches)
58    {
59        return $this->wiki->addToken($this->rule, array(
60                    'text' => $matches[1],
61                    'attr' => array('type' => '') ) );
62    }
63}
64