Skip to content

Commit

Permalink
match \n in #redirect pattern to overcome creole creedyness. #18
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Sep 24, 2016
1 parent d5b70f9 commit 36ebf4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion _test/parser.test.php
Expand Up @@ -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'),
);
}
}
9 changes: 8 additions & 1 deletion syntax.php
Expand Up @@ -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');
}

/**
Expand All @@ -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
Expand Down

0 comments on commit 36ebf4a

Please sign in to comment.