diff --git a/_test/parser.test.php b/_test/parser.test.php index d7780cd..d4093de 100644 --- a/_test/parser.test.php +++ b/_test/parser.test.php @@ -23,7 +23,9 @@ public function test_parser($text, $page) { public function data() { return array( 0 => array('~~REDIRECT>http://google.com~~', 'http://google.com'), - 1 => array('~~REDIRECT>probability_basic_definitions#bayes_theorem~~', 'probability_basic_definitions#bayes_theorem'), + 1 => array("\n~~REDIRECT>probability_basic_definitions#bayes_theorem~~", 'probability_basic_definitions#bayes_theorem'), + 2 => array('#redirect start', 'start'), + 3 => array("\n#redirect start\n", 'start'), ); } } diff --git a/syntax.php b/syntax.php index e2adf02..045727f 100644 --- a/syntax.php +++ b/syntax.php @@ -38,7 +38,11 @@ public function getSort() { * @param string $mode Parser mode */ public function connectTo($mode) { - $this->Lexer->addSpecialPattern('(?:~~REDIRECT>.+?~~|^#(?i:redirect) [^\r\n]+)', $mode, 'plugin_pageredirect'); + // NOTE: each document is surrounted with \n by dokuwiki parser + // so it's safe to use \n in the pattern + // this fixes creole greedyness: + // https://github.com/glensc/dokuwiki-plugin-pageredirect/issues/18#issuecomment-249386268 + $this->Lexer->addSpecialPattern('(?:~~REDIRECT>.+?~~|\n#(?i:redirect) [^\r\n]+)', $mode, 'plugin_pageredirect'); } /** @@ -56,6 +60,9 @@ public function connectTo($mode) { * @return array Return an array with all data you want to use in render */ public function handle($match, $state, $pos, Doku_Handler $handler) { + // strip leading "\n" from creole-compatible pattern + $match = trim($match); + // extract target page from match pattern if($match[0] == '#') { # #REDIRECT PAGE