Fix markdown render-link hook so that it doesn't generate unnecessary whitespace (#203)

* Render-link hook cleanup -- no change in generated site

* Remove unnecessary whitespace
This commit is contained in:
Patrice Chalin 2020-04-21 21:09:38 -04:00 committed by GitHub
parent 4479a02c03
commit 672c22e22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 10 deletions

View File

@ -1,10 +1,15 @@
{{ $link := .Destination }}
{{ $isRemote := strings.HasPrefix $link "http" }}
{{- if not $isRemote -}}
{{ $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 }}"{{ with .Title }} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank"{{ end }}>{{- .Text | safeHTML -}}</a>
{{ $link := .Destination -}}
{{ $isRemote := strings.HasPrefix $link "http" -}}
{{ if not $isRemote -}}
{{ $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 }}"
{{- with .Title }} title="{{ . }}"{{ end -}}
{{ if $isRemote }} target="_blank"{{ end -}}
>
{{- .Text | safeHTML -}}
</a>