Fix some issues with ToC (#8797)

* Allow HTML in ToC

Fixes #4793

* Extract ToC id from the header

This is needed when the id is set explicitly in markdown.
This commit is contained in:
Bjørn Erik Pedersen
2018-06-04 18:35:54 +03:00
committed by k8s-ci-robot
parent 200857de80
commit a7d2dfc4fc
+4 -2
View File
@@ -9,8 +9,10 @@
{{ $section := $.ctx.Scratch.Get "section" }}
{{ $headers := findRE "<h2.*?>(.|\n)*?</h2>" $section }}
{{ range $headers }}
{{ $header := . | replaceRE "</?h2.*?>" "" | htmlUnescape }}
<li><a href="#{{ $header | anchorize }}">{{ $header }}</a></li>
{{ $id := . | strings.TrimPrefix "<h2 id=\"" }}
{{ $id := $id | replaceRE "\">.*" "" }}
{{ $header := . | replaceRE "</?h2.*?>" "" | htmlUnescape | safeHTML }}
<li><a href="#{{ $id }}">{{ $header }}</a></li>
{{ end }}
{{ $.ctx.Scratch.Add "sections" $section }}
{{ end }}