1<?php
2// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
3/**
4 * BBCode: Parses for underlined text.
5 *
6 * This class implements a Text_Wiki_Rule to find source text marked for
7 * strong emphasis (underline) as defined by text surrounded by [u] ... [/u]
8 * On parsing, the text itself is left in place, but the starting and ending
9 * tags are replaced with tokens.
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 * Underlined text 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_Underline 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 =  "#\[u](.*?)\[/u]#i";
45
46
47    /**
48     * Generates a replacement for the matched text.  Token options are:
49     * - 'type' => ['start'|'end'] The starting or ending point of the
50     * emphasized text.  The text itself is left in the source.
51     *
52     * @param array &$matches The array of matches from parse().
53     * @return A pair of delimited tokens to be used as a placeholder in
54     * the source text surrounding the text to be emphasized.
55     * @access public
56     */
57    function process(&$matches)
58    {
59        $start = $this->wiki->addToken($this->rule, array('type' => 'start'));
60        $end = $this->wiki->addToken($this->rule, array('type' => 'end'));
61        return $start . $matches[1] . $end;
62    }
63}
64