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

Hugo 0.141.0 strips apostrophes from image alt strings #13286

Closed
chalin opened this issue Jan 21, 2025 · 2 comments · Fixed by #13289
Closed

Hugo 0.141.0 strips apostrophes from image alt strings #13286

chalin opened this issue Jan 21, 2025 · 2 comments · Fixed by #13289
Assignees
Labels
Milestone

Comments

@chalin
Copy link
Contributor

chalin commented Jan 21, 2025

Attached to this issue is a minimalist Hugo project, hugo-141-alt-issue.zip, with the following markdown in the main index.md file:

![A's and B's](some-image.png)

Here's how Hugo 0.140.2 and 0.141.0 render HTML for the markdown image syntax above:

$ hugo  # v0.140.2
Start building sites … 
hugo v0.140.2-...
$ grep some-image public/index.html 
    <p><img src="some-image.png" alt="A&rsquo;s and B&rsquo;s"></p>
$ _hugo  # alias for v0.141.0
Start building sites … 
hugo v0.141.0-...
$ grep some-image public/index.html
    <p><img src="some-image.png" alt="As and Bs"></p>

Note that Hugo 0.141.0 doesn't generate the &rsquo; in the alt text.

Now comment out the languages entry from the project's hugo.yaml config, and Hugo 0.141.0 will generate the &rsquo; once again:

$ grep -E 'lang|en' hugo.yaml
# languages:
#   en:
#     languageCode: en

$ _hugo                            
Start building sites … 
hugo v0.141.0-...
$ grep some-image public/index.html
    <p><img src="some-image.png" alt="A&rsquo;s and B&rsquo;s"></p>

I'm working under macOS.

/cc @svrnm

@jmooring
Copy link
Member

My notes below assume that:

  1. The Goldmark typographer extension is enabled and in its default configuration.
  2. We're using this markup: [A's and B's](a.jpg).

In an image render hook with v0.138.0:

{{ .Text }} --> A&rsquo;s and B&rsquo;s
{{ .PlainText }} --> A&amp;rsquo;s and B&amp;rsquo;s

Then Goldmark deprecated Node.Text in its version 1.7.8 so we started using Node.PlainText in our v0.139.0:

{{ .Text }} --> A&rsquo;s and B&rsquo;s
{{ .PlainText }} --> As and Bs

For this example the change above didn't affect us because the image render hook was calling Text not PlainText.

Then I made this change in v0.141.0 after @Arty2 pointed out the following in the images section of the CommonMark specification:

Though this spec is concerned with parsing, not rendering, it is recommended that in rendering to HTML, only the plain string content of the image description be used.

But in retrospect I guess I really don't know what "plain string content" means... there's a bit of wiggle room there. Testing the image link above on the Goldmark playground with the typographer extension enabled yields this:

<img src="a.jpg" alt="A&rsquo;s and B&rsquo;s">

So, unless someone has a differing opinion, I think we should revert 8af0474.

@Arty2 You kind of got this ball rolling. Any comments?

@bep
Copy link
Member

bep commented Jan 21, 2025

I guess introduced in 8af0474.

Failing test:

// Issue 13286
func TestImageAltApostrophes(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
[languages]
  [languages.en]
  languageCode = "en"
-- content/p1.md --
---
title: "p1"
---

## Image

![A's and B's](some-image.png)


-- layouts/_default/single.html --
{{ .Content }}
`

	b := hugolib.Test(t, files)

	b.AssertFileContentExact("public/p1/index.html",
		"A&rsquo;s and B&rsquo;s",
	)
}

This is an odd one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants