Files
Bjørn Erik Pedersen b51bdc88cc Make it compatible with Hugo 0.55 (#13680)
This commit adds two backwards compatible changes to prepare for the next Hugo version, most notable:

* All the `File` methods on `Page` has been deprecated and will give a warning in the next Hugo version. Adjust this by changing `.Dir` to ´.File.Dir` and similar.
* Version the capture shortcode to use the old behaviour for markdown rendering of shortcode inner content.
2019-04-08 18:19:05 -07:00

22 lines
703 B
HTML

{{ .ctx.Scratch.Set "sections" slice }}
<ul id="markdown-toc">
{{ range .ctx.Scratch.Get "blocks" }}
{{ if .block }}
{{ $.ctx.Scratch.Set "section" (partial "templates/block" .) }}
{{ else}}
{{ $.ctx.Scratch.Set "section" .content }}
{{ end }}
{{ $section := $.ctx.Scratch.Get "section" }}
{{ $headers := findRE "<h2.*?>(.|\n)*?</h2>" $section }}
{{ range $headers }}
{{ $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 }}
</ul>
{{ range .ctx.Scratch.Get "sections" }}
{{ . }}
{{ end }}