diff --git a/layouts/partials/process-markdown-content.html b/layouts/partials/process-markdown-content.html index 75ba1b08ca..61dbc14ef2 100644 --- a/layouts/partials/process-markdown-content.html +++ b/layouts/partials/process-markdown-content.html @@ -72,9 +72,14 @@ {{- $content = $content | replaceRE `\]\(/content/([^)#]*?)/index\.md` "](https://redis.io/docs/latest/$1" -}} {{- $content = $content | replaceRE `\]\(/content/([^)#]*?)\.md` "](https://redis.io/docs/latest/$1" -}} -{{- /* Markdown images: drop the `{width="..." class="..."}` line render-image.html - reads, which would otherwise reach the output as literal text, then - absolutize the path. */ -}} +{{- /* Fix images - handle both HTML-escaped entities and literal characters */ -}} +{{- /* Pattern for HTML-escaped: {{< image filename="path" [alt="..."] >}} */ -}} +{{- $content = $content | replaceRE "\\{\\{<\\s*image\\s+filename="/?([^&]+)"[^}]*>\\}\\}" "![$1](https://redis.io/docs/latest/$1)" -}} +{{- /* Pattern for literal: {{< image filename="path" [alt="..."] >}} */ -}} +{{- $content = $content | replaceRE `\{\{<\s*image\s+filename="/?([^"]+)"[^}]*>\}\}` "![$1](https://redis.io/docs/latest/$1)" -}} +{{- /* Markdown images that replace the `image` shortcode (DOC-7128): drop the + `{width="..." class="..."}` line render-image.html reads, which would + otherwise reach the output as literal text, then absolutize the path. */ -}} {{- $content = $content | replaceRE `(?m)(!\[[^\]\n]*\]\([^)\n]*\))[ \t]*\n[ \t>]*\{(?:\s*\w+="[^"]*")+\s*\}[ \t]*$` "$1" -}} {{- $content = $content | replaceRE `(!\[[^\]\n]*\]\()/(?:static/)?images/` "${1}https://redis.io/docs/latest/images/" -}} diff --git a/layouts/shortcodes/image.html b/layouts/shortcodes/image.html new file mode 100644 index 0000000000..1b13a857b4 --- /dev/null +++ b/layouts/shortcodes/image.html @@ -0,0 +1,14 @@ +{{ $fname := .Get "filename" | strings.TrimLeft "/" }} +{{ if not (hasPrefix $fname "/") }} + {{ .Scratch.Set "file" (printf "/%s" $fname) }} +{{ else }} + {{ .Scratch.Set "file" $fname }} +{{ end }} +{{- $width := .Get "width" | default "75%" }} + + {{.}} +