{{- $html := .html | string -}}
{{- if .namespace -}}
{{- $prefix := printf "%s-" (md5 .page.Path) -}}
{{- $attributes := `(?:[^"'<>]|"[^"]*"|'[^']*')*` -}}{{- range slice "id" "for" "list" "form" -}}
{{- $html = replaceRE (printf `(<[a-zA-Z]%s\s%s=["'])([^"']*)(["'])` $attributes .) (printf `${1}%s${2}${3}` $prefix) $html -}}
{{- end -}}
{{- $html = replaceRE (printf `(]*(?:\s(?:headers|aria-activedescendant|aria-controls|aria-describedby|aria-details|aria-errormessage|aria-flowto|aria-labelledby|aria-owns)=|url\()[^>]*>` $html -}}
{{- $tag := . -}}
{{- range findRESubmatch `(\s(?:headers|aria-activedescendant|aria-controls|aria-describedby|aria-details|aria-errormessage|aria-flowto|aria-labelledby|aria-owns)=["'])([^"']*)(["'])` $tag -}}
{{- $ids := slice -}}
{{- range findRE `\S+` (index . 2) -}}{{- $ids = $ids | append (printf "%s%s" $prefix .) -}}{{- end -}}
{{- $tag = replace $tag (index . 0) (printf "%s%s%s" (index . 1) (delimit $ids " ") (index . 3)) -}}
{{- end -}}
{{- $tag = replaceRE `url\((["']?)#([^)"'\s]+)(["']?)\)` (printf `url(${1}#%s${2}${3})` $prefix) $tag -}}
{{- if ne $tag . -}}{{- $html = replace $html . $tag -}}{{- end -}}
{{- end -}}
{{- range findRE `(?s)` $html -}}
{{- $html = replace $html . (replaceRE `url\((["']?)#([^)"'\s]+)(["']?)\)` (printf `url(${1}#%s${2}${3})` $prefix) .) -}}
{{- end -}}
{{- end -}}
{{- range findRE `]*\bdata-print-href="[^"]+"[^>]*>` $html -}}
{{- $tag := . -}}
{{- $target := replaceRE `.*\bdata-print-href="([^"]+)".*` `${1}` $tag -}}
{{- if in $.targets $target -}}
{{- $rewritten := replaceRE `(\s)href="[^"]*"` (printf `${1}href="%s"` $target) $tag -}}
{{- $html = replace $html $tag $rewritten -}}
{{- end -}}
{{- end -}}
{{- return ($html | safeHTML) -}}