Merge pull request #3567 from zubron/render-fragments-in-markdown

Correctly render links with fragments on docs pages
This commit is contained in:
David L. Smith-Uchida
2021-04-15 15:20:03 -07:00
committed by GitHub

View File

@@ -1,5 +1,10 @@
{{ $link := .Destination }}
{{ if not (strings.HasPrefix $link "http") }}
{{ $link = (.Page.GetPage .Destination).RelPermalink }}
{{ $url := urls.Parse .Destination }}
{{- if $url.Path -}}
{{ $fragment := "" }}
{{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
{{- with .Page.GetPage $url.Path }}{{ $link = printf "%s%s" .RelPermalink $fragment }}{{ end }}
{{ end }}
{{ end }}
<a href="{{ $link | safeURL }}">{{ .Text | safeHTML }}</a>