diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-01-02 18:57:02 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-01-02 19:11:08 +0300 |
commit | 6f542929dc66b908fc5699ebf30e45da4775a0c8 (patch) | |
tree | 885e8c063d4ab6908ce7a29bf37e79a3d30b2bc1 | |
parent | 54be3ea1162306f86f1e2916e5e6babd58ea7382 (diff) |
Fix ToC with foreign chars
Note that I suspect you would need a recent Hugo version for this fix to work, as Goldmark (the new renderer) has a slightly different ID generator.
Fixes #34
-rw-r--r-- | layouts/_default/list.html | 4 | ||||
-rw-r--r-- | layouts/partials/funcs/toc_from_pages.html | 5 |
2 files changed, 4 insertions, 5 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 3280146..71887cd 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -9,11 +9,11 @@ {{ $headers := partial "funcs/toc_from_pages" .Site.RegularPages }} {{ range $headers }} <li> - <a href="#{{ .title | anchorize }}" class="toc-h{{ .level }} toc-link" data-title="{{ .title }}">{{ .title }}</a> + <a href="#{{ .id }}" class="toc-h{{ .level }} toc-link" data-title="{{ .title }}">{{ .title }}</a> {{if .sub }} <ul class="toc-list-h2"> {{range .sub}} - <li><a href="#{{ .title | anchorize }}" class="toc-h{{ .level }} toc-link" data-title="{{ .title }}">{{ .title }}</a></li> + <li><a href="#{{ .id }}" class="toc-h{{ .level }} toc-link" data-title="{{ .title }}">{{ .title }}</a></li> {{end}} </ul> {{end}} diff --git a/layouts/partials/funcs/toc_from_pages.html b/layouts/partials/funcs/toc_from_pages.html index e86d919..1919a51 100644 --- a/layouts/partials/funcs/toc_from_pages.html +++ b/layouts/partials/funcs/toc_from_pages.html @@ -12,9 +12,8 @@ {{ range $combined }} {{ $level := int (substr . 2 1) }} {{ if le $level 2 }} - {{ $title := . | replaceRE "</?h\\d.*?>" "" | htmlUnescape | safeHTML }} - {{ $item := dict "level" $level "title" $title }} - + {{ $idTitle := split (. | replaceRE "<h\\d id=\"(.*?)\">(.*)</h\\d>" "$1|$2") "|" }} + {{ $item := dict "level" $level "id" (index $idTitle 0) "title" (index $idTitle 1) }} {{ if eq $level 1 }} {{ if ne $previousLevel 0 }} {{ $tocItem := merge $previousH1 (dict "sub" $h2s) }} |