{{$dashedurl := replace .Destination "%20" "-" }}
{{$external := strings.HasPrefix $dashedurl "http" }}
{{- if $external -}}
{{ .Text | safeHTML }}
{{- else -}}
{{$trimmed := strings.TrimSuffix ".md" (.Destination | safeURL)}}
{{$spacedurl := replace $trimmed "%20" " " }}
{{$fixedUrl := (cond (hasPrefix $spacedurl "/") $spacedurl (print "/" $spacedurl)) | urlize}}
{{$nonexistent := eq (.Page.GetPage $spacedurl).RelPermalink ""}}
{{$rooted := default $spacedurl ((.Page.GetPage $spacedurl).RelPermalink) }}
{{- .Text | safeHTML -}}
{{- end -}}