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

unexpected trailing dash in auto heading ID for "# heading #" #6798

Closed
lukpank opened this issue Jan 24, 2020 · 4 comments · Fixed by #7459
Closed

unexpected trailing dash in auto heading ID for "# heading #" #6798

lukpank opened this issue Jan 24, 2020 · 4 comments · Fixed by #7459
Milestone

Comments

@lukpank
Copy link

lukpank commented Jan 24, 2020

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

$ hugo version
Hugo Static Site Generator v0.63.1/extended linux/amd64 BuildDate: unknown

The issue originates in the following commit:

a82d2700 markup/goldmark: Make auto IDs GitHub compatible

Does this issue reproduce with the latest release?

Yes

Problematic document

Having the following markdown document (note trailing space after "Heading2"):

# Heading1 #
# Heading2 

Correct auto heading IDs with blackFriday

If I turn on the "blackFriday" markdown parser with:

[markup]
  defaultMarkdownHandler = "blackFriday"

The generated heading IDs are both correct (no trailing dash):

$ ( hugo && grep 'h1 id=' public/tmp/index.html ) | tail -2
<h1 id="heading1">Heading1</h1>
<h1 id="heading2">Heading2</h1>

Incorrect heading ID with goldmark

But If I use the default "goldmark" Markdown parser the generated ID
for the first heading contains unexpected trailing dash:

$ ( hugo && grep 'h1 id=' public/tmp/index.html ) | tail -2
  <h1 id="heading1-">Heading1</h1>
<h1 id="heading2">Heading2</h1>

Input to Generate

I checked what enters (*idFactory).Generate (from markup/goldmark/autoid.go) and for the first heading the input converted to string is "Heading1 " (has a trailing space) and for the second heading it is "Heading2".

@obar
Copy link

obar commented Jan 31, 2020

Ran into the same thing (trailing whitespace not trimmed in symmetric heading style) and my solution was to use the asymmetric heading style. Any reason not to file this as a bug in goldmark and close this one?

@stale
Copy link

stale bot commented May 31, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label May 31, 2020
@stale stale bot closed this as completed Jul 3, 2020
@jmooring
Copy link
Member

jmooring commented Jul 4, 2020

Please reopen:

  • This is reproducible with 0.73
  • It does not appear to be a Goldmark bug (hugo-github-issue-6798.go.txt)
  • Reproducible with autoHeadingIDType set to either github or github-ascii
  • Not reproducible with autoHeadingIDType set to blackfriday

Examples:

Markdown Expected HTML Actual HTML
# Foo # <h1 id="foo">Foo</h1> <h1 id="foo-">Foo</h1>
# Bar {.foo} <h1 class="foo" id="bar">Bar</h1> <h1 class="foo" id="bar-">Bar</h1>

@bep bep reopened this Jul 5, 2020
@stale stale bot removed the Stale label Jul 5, 2020
@bep bep added the Bug label Jul 5, 2020
@bep bep added this to the v0.74 milestone Jul 5, 2020
@bep bep closed this as completed in #7459 Jul 5, 2020
bep pushed a commit that referenced this issue Jul 5, 2020
Applicable when autoHeadingIDType is either `github` or `github-ascii`.

When autoHeadingIDType is `blackfriday`, the existing code removes
trailing whitespace while iterating through the characters, using
a boolean "futureDash" mechanism.

Fixes #6798
@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 Jan 31, 2022
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.

4 participants