From 06917fcef4c96db29b53fef1de68c2a61a67cd65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= <grosse@cosmocode.de> Date: Tue, 5 Sep 2017 19:16:52 +0200 Subject: [PATCH] fix: fix regex to return table secedit buttons Since the hid is optional, it must also be optional in the regex. Also this commit introduced named capture groups to make it more obvious which part of the regex captures what. Also there is now an explicit hid generated for tables, to enable jumping to the correct section after finishing editing. This was broken in 2571786c763e04c7abbf27c2245a5720878dc3f1 or #1966 respectively. Known Issues: * since both title and hid are optional, a hid may be misinterpreted as a title if the title is not generated. --- inc/html.php | 18 +++++++++++------- inc/parser/xhtml.php | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/inc/html.php b/inc/html.php index 9fa121db9..d370d48b2 100644 --- a/inc/html.php +++ b/inc/html.php @@ -91,7 +91,7 @@ function html_denied() { function html_secedit($text,$show=true){ global $INFO; - $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )(?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; + $regexp = '#<!-- EDIT(?<secid>\d+) (?<target>[A-Z_]+) (?:"(?<name>[^"]*)" )?(?:"(?<hid>[^"]*)" )?\[(?<range>\d+-\d*)\] -->#'; if(!$INFO['writable'] || !$show || $INFO['rev']){ return preg_replace($regexp,'',$text); @@ -112,12 +112,16 @@ function html_secedit($text,$show=true){ * @triggers HTML_SECEDIT_BUTTON */ function html_secedit_button($matches){ - $data = array('secid' => $matches[1], - 'target' => strtolower($matches[2]), - 'hid' => strtolower($matches[4]), - 'range' => $matches[count($matches) - 1]); - if (count($matches) === 6) { - $data['name'] = $matches[3]; + $data = array('secid' => $matches['secid'], + 'target' => strtolower($matches['target']), + 'range' => $matches['range']); + + if (!empty($matches['hid'])) { + $data['hid'] = strtolower($matches['hid']); + } + + if (!empty($matches['name'])) { + $data['name'] = $matches['name']; } return trigger_event('HTML_SECEDIT_BUTTON', $data, diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index dbac1a982..042aba111 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1339,7 +1339,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $class .= ' ' . $classes; } if($pos !== null) { - $class .= ' '.$this->startSectionEdit($pos, 'table'); + $hid = $this->_headerToLink($class, true); + $class .= ' '.$this->startSectionEdit($pos, 'table', '', $hid); } $this->doc .= '<div class="'.$class.'"><table class="inline">'. DOKU_LF; -- GitLab