Skip to content

Commit 391549a

Browse files
author
Mizunashi Mana
committed
Support dokuwiki escaping on markdown default
1 parent e173de3 commit 391549a

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

syntax.php

+25-8
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,42 @@ public function getPluginName() {
3333
return $this->getInfo()['base'];
3434
}
3535

36+
public function getPluginMode() {
37+
return 'plugin_' . $this->getPluginName();
38+
}
39+
3640
public function connectTo($mode) {
3741
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());
3945
} else {
40-
$this->Lexer->addEntryPattern('<markdown>(?=.*</markdown>)', $mode, 'plugin_' . $this->getPluginName());
46+
$this->Lexer->addEntryPattern('<markdown>(?=.*</markdown>)', $mode, $this->getPluginMode());
4147
}
4248
}
4349

4450
public function postConnect() {
51+
$pluginBaseMode = 'plugin_' . $this->getPluginName();
52+
4553
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());
4756
} else {
48-
$this->Lexer->addExitPattern('</markdown>', 'plugin_' . $this->getPluginName());
57+
$this->Lexer->addExitPattern('</markdown>', $pluginBaseMode);
4958
}
5059
}
5160

5261
public function handle($match, $state, $pos, Doku_Handler $handler) {
5362
switch ($state) {
5463
case DOKU_LEXER_UNMATCHED:
5564
$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 {
5772
$new_pos = $new_pos - strlen('<markdown>');
5873
}
5974

@@ -100,10 +115,12 @@ protected function renderWithRenderer(Doku_Renderer $renderer, $match, $data) {
100115
];
101116

102117
$result = Markdown::parseWithRenderer($renderer, $match, $data, $context);
103-
/*echo '<pre>';
104-
var_dump($match);
118+
/*
119+
echo '<pre>';
120+
var_dump(htmlspecialchars($match));
105121
var_dump(htmlspecialchars($result));
106-
echo '</pre>';*/
122+
echo '</pre>';
123+
*/
107124

108125
return true;
109126
}

0 commit comments

Comments
 (0)