Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quotation marks and apostrophes in image alt-text are double-escaped with Goldmark Typographer #11045

Closed
ObjectBoxPC opened this issue May 29, 2023 · 2 comments · Fixed by #11049

Comments

@ObjectBoxPC
Copy link

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.112.5-48e33e10af2feb2a0e1c32d04880ed016619f2d8 linux/amd64 BuildDate=2023-05-29T07:27:36Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Description

Quotation marks and apostrophes appearing in image alt-text are double-escaped.

The following Markdown:

!["They didn't even say 'hello'!" I exclaimed.](https://example.com/image.jpg)

is rendered as:

<p><img src="https://example.com/image.jpg" alt="&amp;ldquo;They didn&amp;rsquo;t even say &amp;lsquo;hello&amp;rsquo;!&amp;rdquo; I exclaimed."></p>

Expected output is:

<p><img src="https://example.com/image.jpg" alt="&ldquo;They didn&rsquo;t even say &lsquo;hello&rsquo;!&rdquo; I exclaimed."></p>

This is not a bug in Goldmark itself, as using that library directly produces the expected output. The bug actually was previously present in Goldmark (GitHub issue) but it has been fixed, so now it appears that this bug now has to do with how Hugo handles the data.

@jmooring
Copy link
Member

Confirmed that Goldmark outptut is correct:

main.go
import (
	"bytes"
	"fmt"

	"github.com/yuin/goldmark"
	"github.com/yuin/goldmark/extension"
)

func main() {
	md := goldmark.New(
		goldmark.WithExtensions(
			extension.Typographer,
		),
	)

	input := `![He said, "Eat at Joe's."](x)`

	var buf bytes.Buffer
	if err := md.Convert([]byte(input), &buf); err != nil {
		panic(err)
	}

	fmt.Println(buf.String())

}

Confirmed that this is not Go's html/template package doing its thing by setting:

[outputFormats.html]
isPlainText = true

Note that this only affects the attribute value.

Markdown

![He said, "Eat at Joe's."](x)

[He said, "Eat at Joe's."](x)

Rendered

<img src="x" alt="He said, &amp;ldquo;Eat at Joe&amp;rsquo;s.&amp;rdquo;">

<a href="x">He said, &ldquo;Eat at Joe&rsquo;s.&rdquo;</a>

Example

git clone --single-branch -b hugo-github-issue-11045 https://github.com/jmooring/hugo-testing hugo-github-issue-11045
cd hugo-github-issue-11045
hugo server

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants