Skip to content

Commit

Permalink
Fix some issues with ToC (kubernetes#8797)
Browse files Browse the repository at this point in the history
* Allow HTML in ToC

Fixes kubernetes#4793

* Extract ToC id from the header

This is needed when the id is set explicitly in markdown.
  • Loading branch information
bep authored and k8s-ci-robot committed Jun 4, 2018
1 parent 200857d commit a7d2dfc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions layouts/partials/templates/blocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit a7d2dfc

Please sign in to comment.