Custom Output escaping characters as HTML entities

I’m seeing some unexpected behavior with custom output formats.

I have two custom formats that are nearly identical, but behave differently:

  [ outputFormats.plain ]
    name = "plain"
    isPlainText = true
    isHTML = false
    mediaType = "text/plain"
    permalinkable = true
    path = "txt/"
  [ outputFormats.gemini ]
    name = "GEMINI"
    isPlainText = true
    isHTML = false
    mediaType = "text/gemini"
    protocol = "gemini://"
    permalinkable = true
    path = "gemini/"

The plain output converts single and double quotes to their corresponding HTML entities, while the gemini output does not. Even when both use a copy of the same template:

# {{ .Title }}

{{ $content := .RawContent -}}
{{ $content := $content | replaceRE "`(.+?)`" "$1" -}}
{{ $content := $content | replaceRE "`" "```" -}}
{{ $content := $content | replaceRE "\\*(.+?)\\*" "$1" -}}
{{ $content := $content | replaceRE " \\[(.+?)\\]\\((.+?)\\)" "\n\n=> $2 $1\n\n" -}}
{{ $content := $content | replaceRE "\\[(.+?)\\]\\((.+?)\\)" "=> $2 $1" -}}
{{ $content := $content | replaceRE "<!--more-->" "" -}}
{{ $content }}

hugo v0.89.4+extended linux/amd64

The escaping of special characters happens due to the default behaviour of go text templates package -that is considered a feature-.

I would try a couple of things in your case.

  1. Use literal strings for your regex, meaning wrap them in backticks not double quotes.
  2. If the above does not work try processing the regex output with the htmlUnescape function.

I get the same result with {{ $content }} and {{ $content | htmlUnescape }} but only in the plain output type. That’s the part that’s unexpected. Why would those two content types produce different output, even when using the same template?

I am unable to reproduce the behavior, so perhaps my setup is different:

git clone --single-branch -b hugo-forum-topic-36050 https://github.com/jmooring/hugo-testing hugo-forum-topic-36050
cd hugo-forum-topic-36050
hugo 
cat public/gemini/post/test/index.gem
cat public/txt/post/test/index.txt