Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
172 jpm 1
<?php
2
// $Id: Code.php,v 1.1 2004-11-24 19:43:09 jpm Exp $
3
 
4
 
5
/**
6
*
7
* This class implements a Text_Wiki_Parse to find sections marked as code
8
* examples.  Blocks are marked as the string <code> on a line by itself,
9
* followed by the inline code example, and terminated with the string
10
* </code> on a line by itself.  The code example is run through the
11
* native PHP highlight_string() function to colorize it, then surrounded
12
* with <pre>...</pre> tags when rendered as XHTML.
13
*
14
* @author Paul M. Jones <pmjones@ciaweb.net>
15
*
16
* @package Text_Wiki
17
*
18
*/
19
 
20
class Text_Wiki_Parse_Code extends Text_Wiki_Parse {
21
 
22
 
23
    /**
24
    *
25
    * The regular expression used to find source text matching this
26
    * rule.
27
    *
28
    * @access public
29
    *
30
    * @var string
31
    *
32
    */
33
 
34
    var $regex = '/^(%%\((\w*?)\))(.+?)(%%)(\s|$)/Umsi';
35
 
36
 
37
    /**
38
    *
39
    * Generates a token entry for the matched text.  Token options are:
40
    *
41
    * 'text' => The full matched text, not including the <code></code> tags.
42
    *
43
    * @access public
44
    *
45
    * @param array &$matches The array of matches from parse().
46
    *
47
    * @return A delimited token number to be used as a placeholder in
48
    * the source text.
49
    *
50
    */
51
 
52
    function process(&$matches)
53
    {
54
        if ($matches[2] == '') {
55
            $code = $this->wiki->addToken(
56
                    $this->rule,
57
                    array(
58
                        'text' => $matches[3],
59
                        'attr' => array('type' => '')
60
                    )
61
                );
62
        } else {
63
            $code = $this->wiki->addToken(
64
                    $this->rule,
65
                    array(
66
                        'text' => $matches[3],
67
                        'attr' => array('type' => $matches[2])
68
                    )
69
                );
70
        }
71
 
72
        return $code . $matches[5];
73
    }
74
}
75
?>