{{- $rel := "" -}}
{{- $type := "" -}}
{{- $fragment := "" -}}
{{- $link := .Destination -}}
{{- $target := urls.Parse $link -}}
{{- $self := urls.Parse .Page.Site.BaseURL -}}
{{- $prurl := eq (findRE `^/\w` $link | len) 0 -}}
{{- $local := or (eq $target.Host $self.Host) (and (strings.HasPrefix $link "/") (not $prurl)) -}}
{{- $remote := not $local -}}
{{- if $remote -}}
{{- $rel = .Page.Site.Params.site.referrer.anchor -}}
{{- else -}}
{{- $type = "internal" -}}
{{- end -}}
{{- if and $local $target.Path -}}
{{- with .Page.GetPage (strings.TrimRight "/" $target.Path) -}}
{{- with $target.Fragment -}} {{- $fragment = printf "#%s" . -}} {{- end -}}
{{- $link = printf "%s%s" .Permalink $fragment -}}
{{- else -}}
{{- $type = "broken" -}}
{{- if $feed := not (strings.HasPrefix $link "/") -}}
{{- $link = .Destination | absURL -}}
{{- else -}}
{{- $link = strings.TrimLeft "/" .Destination | relURL -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{ .Text | safeHTML }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}