1 | <?php
|
---|
2 | /**
|
---|
3 | * HTML Comment Plugin: allows HTML comments to be retained in the output
|
---|
4 | *
|
---|
5 | * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
---|
6 | * @author Christopher Arndt <[email protected]>
|
---|
7 | */
|
---|
8 |
|
---|
9 | if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
|
---|
10 | if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
|
---|
11 | require_once(DOKU_PLUGIN.'syntax.php');
|
---|
12 |
|
---|
13 | define('HTMLCOMMENT_SAFE', true);
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * All DokuWiki plugins to extend the parser/rendering mechanism
|
---|
17 | * need to inherit from this class
|
---|
18 | */
|
---|
19 | class syntax_plugin_htmlcomment extends DokuWiki_Syntax_Plugin {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * return some info
|
---|
23 | */
|
---|
24 | function getInfo(){
|
---|
25 | return array(
|
---|
26 | 'author' => 'Christopher Arndt',
|
---|
27 | 'email' => '[email protected]',
|
---|
28 | 'date' => '2005-10-08',
|
---|
29 | 'name' => 'HTML Comment Plugin',
|
---|
30 | 'desc' => 'allows HTML comments to be retained in the output',
|
---|
31 | 'url' => 'http://wiki.splitbrain.org/plugin:html_comment',
|
---|
32 | );
|
---|
33 | }
|
---|
34 |
|
---|
35 | function getType() {
|
---|
36 | return 'substition';
|
---|
37 | }
|
---|
38 |
|
---|
39 | function getSort() {
|
---|
40 | return 325;
|
---|
41 | }
|
---|
42 |
|
---|
43 | function connectTo($mode) {
|
---|
44 | $this->Lexer->addSpecialPattern("<\!--.*?-->", $mode, 'plugin_htmlcomment');
|
---|
45 | $this->Lexer->addSpecialPattern("%\!--.*?--%", $mode, 'plugin_htmlcomment');
|
---|
46 | $this->Lexer->addSpecialPattern("<br/>", $mode, 'plugin_htmlcomment');
|
---|
47 | }
|
---|
48 |
|
---|
49 | function handle($match, $state, $pos, &$handler) {
|
---|
50 | if ($state == DOKU_LEXER_SPECIAL) {
|
---|
51 | if ($match == '<br/>')
|
---|
52 | {
|
---|
53 | return array('newline',$match);
|
---|
54 | }
|
---|
55 | if (strpos($match, '%!--') !== false)
|
---|
56 | {
|
---|
57 | $state = 'displaycomment';
|
---|
58 | }
|
---|
59 | // strip <!-- from start and --> from end
|
---|
60 | $match = substr($match,4,-3);
|
---|
61 | return array($state, $match);
|
---|
62 | }
|
---|
63 | return array();
|
---|
64 | }
|
---|
65 |
|
---|
66 | function render($mode, &$renderer, $data) {
|
---|
67 | if ($mode == 'xhtml') {
|
---|
68 | list($state, $match) = $data;
|
---|
69 | if ($state == 'newline')
|
---|
70 | {
|
---|
71 | $renderer->doc .= $match;
|
---|
72 | return true;
|
---|
73 | }
|
---|
74 | if ($state == 'displaycomment')
|
---|
75 | {
|
---|
76 | $renderer->doc .= '<!--';
|
---|
77 | }
|
---|
78 | else
|
---|
79 | {
|
---|
80 | $renderer->doc .= '<!--';
|
---|
81 | }
|
---|
82 | if (HTMLCOMMENT_SAFE) {
|
---|
83 | $renderer->doc .= $renderer->_xmlEntities($match);
|
---|
84 | } else {
|
---|
85 | $renderer->doc .= $match;
|
---|
86 | }
|
---|
87 | if ($state == 'displaycomment')
|
---|
88 | {
|
---|
89 | $renderer->doc .= '-->';
|
---|
90 | }
|
---|
91 | else
|
---|
92 | {
|
---|
93 | $renderer->doc .= '-->';
|
---|
94 | }
|
---|
95 | return true;
|
---|
96 | }
|
---|
97 | return false;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | ?>
|
---|