@@ -33,27 +33,42 @@ public function getPluginName() {
33
33
return $ this ->getInfo ()['base ' ];
34
34
}
35
35
36
+ public function getPluginMode () {
37
+ return 'plugin_ ' . $ this ->getPluginName ();
38
+ }
39
+
36
40
public function connectTo ($ mode ) {
37
41
if ($ this ->getConf ('markdown_default ' )) {
38
- $ this ->Lexer ->addEntryPattern ('\\A. ' , $ mode , 'plugin_ ' . $ this ->getPluginName ());
42
+ $ this ->Lexer ->addEntryPattern ('\\A(?!.*</script>). ' , $ mode , $ this ->getPluginMode ());
43
+ $ this ->Lexer ->addEntryPattern ('<!DOCTYPE markdown> ' , $ mode , $ this ->getPluginMode ());
44
+ $ this ->Lexer ->addEntryPattern ('</script> ' , $ mode , $ this ->getPluginMode ());
39
45
} else {
40
- $ this ->Lexer ->addEntryPattern ('<markdown>(?=.*</markdown>) ' , $ mode , ' plugin_ ' . $ this ->getPluginName ());
46
+ $ this ->Lexer ->addEntryPattern ('<markdown>(?=.*</markdown>) ' , $ mode , $ this ->getPluginMode ());
41
47
}
42
48
}
43
49
44
50
public function postConnect () {
51
+ $ pluginBaseMode = 'plugin_ ' . $ this ->getPluginName ();
52
+
45
53
if ($ this ->getConf ('markdown_default ' )) {
46
- $ this ->Lexer ->addExitPattern ('\\z ' , 'plugin_ ' . $ this ->getPluginName ());
54
+ $ this ->Lexer ->addExitPattern ('\\z ' , $ this ->getPluginMode ());
55
+ $ this ->Lexer ->addExitPattern ('<script type="text/x-dokuwiki"> ' , $ this ->getPluginMode ());
47
56
} else {
48
- $ this ->Lexer ->addExitPattern ('</markdown> ' , ' plugin_ ' . $ this -> getPluginName () );
57
+ $ this ->Lexer ->addExitPattern ('</markdown> ' , $ pluginBaseMode );
49
58
}
50
59
}
51
60
52
61
public function handle ($ match , $ state , $ pos , Doku_Handler $ handler ) {
53
62
switch ($ state ) {
54
63
case DOKU_LEXER_UNMATCHED :
55
64
$ new_pos = $ pos ;
56
- if (!$ this ->getConf ('markdown_default ' )) {
65
+ if ($ this ->getConf ('markdown_default ' )) {
66
+ if (preg_match ('|^</script>| ' , $ match )) {
67
+ $ new_pos = $ new_pos - strlen ('</script> ' );
68
+ } else if (preg_match ('|^<!DOCTYPE markdown>| ' , $ match )) {
69
+ $ new_pos = $ new_pos - strlen ('<!DOCTYPE markdown> ' );
70
+ }
71
+ } else {
57
72
$ new_pos = $ new_pos - strlen ('<markdown> ' );
58
73
}
59
74
@@ -100,10 +115,12 @@ protected function renderWithRenderer(Doku_Renderer $renderer, $match, $data) {
100
115
];
101
116
102
117
$ result = Markdown::parseWithRenderer ($ renderer , $ match , $ data , $ context );
103
- /*echo '<pre>';
104
- var_dump($match);
118
+ /*
119
+ echo '<pre>';
120
+ var_dump(htmlspecialchars($match));
105
121
var_dump(htmlspecialchars($result));
106
- echo '</pre>';*/
122
+ echo '</pre>';
123
+ */
107
124
108
125
return true ;
109
126
}
0 commit comments