Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 jpm 1
<?php
2
// $Id: Code.php,v 1.1 2005-01-20 19:43:20 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 = '/^(\<code( .+)?\>)\n(.+)\n(\<\/code\>)(\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
        // are there additional attribute arguments?
55
        $args = trim($matches[2]);
56
 
57
        if ($args == '') {
58
            $options = array(
59
                'text' => $matches[3],
60
                'attr' => array('type' => '')
61
            );
62
        } else {
63
            $options = array(
64
                'text' => $matches[3],
65
                'attr' => $this->getAttrs($args)
66
            );
67
        }
68
 
69
        return $this->wiki->addToken($this->rule, $options) . $matches[5];
70
    }
71
}
72
?>