{{- $content := .content -}} {{- $page := .page -}} {{- /* Convert link lists */ -}} {{- $listPattern := `(?m)^\* \[([^\]]+)\]\[(\d+)\]$` -}} {{- range findRE $listPattern $content }} {{- /* Extract text and reference number */ -}} {{- $fullMatch := . -}} {{- $text := replaceRE $listPattern `$1` . -}} {{- $refNum := replaceRE $listPattern `$2` . -}} {{- /* Step 2: Find the corresponding reference link */ -}} {{- $refPattern := printf `(?m)^\[%s\]: (.+)$` $refNum -}} {{- $refMatch := findRE $refPattern $content -}} {{- if gt (len $refMatch) 0 }} {{- $url := replaceRE $refPattern `$1` (index $refMatch 0) -}} {{- /* Step 3: Replace original list item with => link format */ -}} {{- $newLine := printf "=> %s %s" $url $text -}} {{- $content = replace $content $fullMatch $newLine -}} {{- /* Step 4: Remove the reference definition */ -}} {{- $content = replace $content (index $refMatch 0) "" -}} {{- end -}} {{- end -}} {{- /* Convert links */ -}} {{- $content = $content | replaceRE `([^\w])\[([^\]]+)\]\[(\d+)\]` "$1$2[$3]" -}} {{- $content = $content | replaceRE `(?m)^\[(\d+)\]: (.*)$` "=> $2 [$1] $2" -}} {{- $content = $content | replaceRE `\[([^\]]+)\]\([^\)]+\)` "$1" -}} {{- /* Replace audio tags */ -}} {{- $audioRE := `` -}} {{- range findRE $audioRE $content -}} {{- $url := . | replaceRE $audioRE "$1" | replaceRE ` ` "%20" -}} {{- $title := . | replaceRE $audioRE "$2" -}} {{- $content = replace $content . (printf "=> %s %s" $url (substr $title 0 -4)) -}} {{- end -}} {{- /* Photo processing */ -}} {{- range findRE `{{<(dither|thumbnail) [^/]+/>}}` $content -}} {{- $rendered := $page.RenderString . -}} {{- $url := $rendered | replaceRE `(?s).*src="([^"]+)".*` "=> $1" -}} {{- $content = replace $content . $url -}} {{- end -}} {{- /* Misc. markup fixes */ -}} {{- $content = $content | replaceRE `\n+` "" -}} {{- $content = $content | replaceRE `(?m)^ >` ">" -}} {{- $content = $content | replaceRE `(?m)^ \*` "* ⇢" -}} {{- $content = $content | replaceRE `(?m)^- ` "* " -}} {{- $content = $content | replaceRE `(?m)^[\*-]{3}$` "✱ ✱ ✱" -}} {{- $content = $content | replaceRE `=> (/.+\.pdf)` (printf "=> %s$1" site.BaseURL) -}} {{- $content = $content | replaceRE `(?m)\n{3,}` "\n\n" }} {{- $content | safeHTML -}}