diff options
author | n-peugnet <n.peugnet@free.fr> | 2020-04-08 17:22:41 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2020-04-08 17:22:41 +0200 |
commit | bfa7d5b2b22b2286faba00884925ff7ecb9392cb (patch) | |
tree | d772a8c633f2410871e38444ca08b8a22637e8b0 /app/class/Modelrender.php | |
parent | ef4d9d383a92a6759ee6e6b2961d5b8e1b9f5db6 (diff) | |
download | wcms-bfa7d5b2b22b2286faba00884925ff7ecb9392cb.tar.gz wcms-bfa7d5b2b22b2286faba00884925ff7ecb9392cb.zip |
fix: SUMMARY does not work with custom header Ids
Fixes #80
Diffstat (limited to 'app/class/Modelrender.php')
-rw-r--r-- | app/class/Modelrender.php | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php index 1721e4e..091179d 100644 --- a/app/class/Modelrender.php +++ b/app/class/Modelrender.php @@ -438,11 +438,19 @@ class Modelrender extends Modelpage } $text = preg_replace_callback( - '/<h([' . $min . '-' . $max . '])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[' . $min . '-' . $max . ']>/mU', + "/<h([$min-$max])((.*)id=\"([^\"]*)\"(.*)|.*)>(.+)<\/h[$min-$max]>/mU", function ($matches) { - $cleanid = idclean($matches[4]); - $this->sum[] = new Header($cleanid, intval($matches[1]), $matches[4]); - return '<h' . $matches[1] . $matches[2] . ' id="' . $cleanid . '">' . $matches[4] . '</h' . $matches[1] . '>'; + $level = $matches[1]; + $beforeid = $matches[3]; + $id = $matches[4]; + $afterid = $matches[5]; + $content = $matches[6]; + // if no custom id is defined, use idclean of the content as id + if (empty($id)) { + $id = idclean($content); + } + $this->sum[] = new Header($id, intval($level), $content); + return "<h$level $beforeid id=\"$id\" $afterid>$content</h$level>"; }, $text ); |