File: html.php

package info (click to toggle)
horde3 3.1.3-4etch7
  • links: PTS
  • area: main
  • in suites: etch
  • size: 22,876 kB
  • ctags: 18,071
  • sloc: php: 75,151; xml: 2,979; sql: 1,069; makefile: 79; sh: 64
file content (106 lines) | stat: -rw-r--r-- 3,137 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php

require_once dirname(__FILE__) . '/../Formatter.php';

/**
 * The Text_reST_Formatter_html:: class is the HTML formatter.
 *
 * $Horde: framework/Text_reST/reST/Formatter/html.php,v 1.6.12.5 2006/01/01 21:28:39 jan Exp $
 *
 * Copyright 2003-2006 Jason M. Felice <jfelice@cronosys.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you did not
 * receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Jason M. Felice <jfelice@cronosys.com>
 * @package Text_reST
 */
class Text_reST_Formatter_html extends Text_reST_Formatter {

    /**
     * The current output charset.
     *
     * @var string
     */
    var $_charset = null;

    function format(&$node, $charset = null)
    {
        if (!isset($charset)) {
            $charset = $this->_charset;
        }

        if (is_string($node)) {
            if (isset($charset)) {
                return @htmlspecialchars($node, ENT_QUOTES, $charset);
            } else {
                return htmlspecialchars($node, ENT_QUOTES);
            }
        }

        switch ($node->_type) {
        case 'Document':
            return $this->_children($node);

        case 'Heading':
            $level = $node->getProperty('level');
            return '<h' . $level . '>' . $this->_children($node) . '</h' .
                $level . '>';

        case 'Link':
            return '<a href="' .
                (isset($charset) ?
                 @htmlspecialchars($node->getProperty('href'), ENT_QUOTES, $charset) :
                 htmlspecialchars($node->getProperty('href'), ENT_QUOTES)) .
                '">' .
                $this->_children($node) . '</a>';

        case 'Literal-Block':
            list($text) = $node->_children;
            return '<pre>' . (isset($charset) ?
                              @htmlspecialchars($text, ENT_QUOTES, $charset) :
                              htmlspecialchars($text, ENT_QUOTES)) . '</pre>';

        case 'Paragraph':
            return "<p>" . $this->_children($node) . "</p>";

        case 'Interpreted-Text':
            switch ($node->getProperty('role')) {
            case 'emphasis':
                return '<em>' . $this->_children($node) . '</em>';

            case 'literal':
                return '<tt>' . $this->_children($node) . '</tt>';

            case 'strong':
                return '<strong>' . $this->_children($node) . '</strong>';

            case 'superscript':
                return '<sup>' . $this->_children($node) . '</sup>';

            case 'subscript':
                return '<sub>' . $this->_children($node) . '</sub>';

            case 'title-reference':
                return '<cite>' . $this->_children($node) . '</cite>';

            default:
                // XXX: Issue a warning.
                return $this->_children($node);
            }

        case 'Section':
            return $this->_children($node);
        }
    }

    function _children(&$node)
    {
        $result = '';
        foreach ($node->_children as $child) {
            $result .= $this->format($child);
        }
        return $result;
    }

}