How can I add rel=nofollow or target=blank or rel=external or other similar attributes to specific links in my posts (in markdown)?

layouts/_default/_markup/render-link.html

{{- $parsedTitle := dict -}}
{{- with .Title -}}
  {{- $parsedTitle = partial "functions/parse-title-attribute.html" . -}}
{{- end -}}

<a href="{{ .Destination | safeURL }}"
  {{- with $parsedTitle.title }} title="{{ . }}"{{- end -}}
  {{- with $parsedTitle.attributes -}}
    {{- range $k, $v := . -}}
      {{- printf " %s=%q" $k $v | safeHTMLAttr -}}
    {{- end -}}
  {{- end -}}
  >{{ .Text | safeHTML }}</a>

{{- /* Strip trailing space. */ -}}

layouts/partials/functions/parse-title-attribute.html

{{/* Split .Title into two parts, title and attributes. */}}
{{- $parts := split . "{" -}}
{{- $parts = apply $parts "trim" "." " " -}}
{{- $parts = apply $parts "trim" "." "}" -}}

{{/* Extract title into a string. */}}
{{- $title := index $parts 0 -}}

{{/* Extract attributes into a dictionary. */}}
{{- $temp := index $parts 1 -}}
{{- $temp = split $temp "'" -}}
{{- $temp = first (sub (len $temp) 1) $temp -}}
{{- $temp = apply $temp "replace" "." "=" "" -}}
{{- $temp = apply $temp "trim" "." " " -}}
{{- $attributes := dict -}}
{{- if $temp -}}
  {{- range (seq 0 2 (sub (len $temp) 1)) -}}
    {{- $attributes = merge $attributes (dict (index $temp . ) (index $temp (add 1 .))) -}}
  {{- end -}}
{{- end -}}

{{- $parsedTitle := dict "title" $title "attributes" $attributes -}}
{{- return $parsedTitle -}}

This works with all of these:

[Hugo Forum](https://discourse.gohugo.io/ "The Hugo Forum {rel='nofollow' foo='bar'}")
[Hugo Forum](https://discourse.gohugo.io/ "The Hugo Forum {rel='nofollow'}")
[Hugo Forum](https://discourse.gohugo.io/ "{rel='nofollow'}")
[Hugo Forum](https://discourse.gohugo.io/ "Hello World")
[Hugo Forum](https://discourse.gohugo.io/ " ")
[Hugo Forum](https://discourse.gohugo.io/ "")
[Hugo Forum](https://discourse.gohugo.io/)
6 Likes