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

Anchors are automatically generated for headings #318

Open
tysongach opened this issue Oct 18, 2024 · 3 comments
Open

Anchors are automatically generated for headings #318

tysongach opened this issue Oct 18, 2024 · 3 comments

Comments

@tysongach
Copy link

Hello,

I’ve just installed the gem into a Rails app and without passing in any options, Commonmarker is generating HTML headings with an anchor link inside of them:

% bin/rails c
Loading development environment (Rails 7.2.1.1)
app(dev)> Commonmarker.to_html("# Foo")
=> "<h1><a href=\"#foo\" aria-hidden=\"true\" class=\"anchor\" id=\"foo\"></a>Foo</h1>\n"

I was expecting this:

<h1>Foo</h1>

The output is surprising to me because there is no mention of these anchors in the CommonMark spec or in the GitHub Flavored Markdown spec.

If you put the example above into the playground/interactive dingus on the CommonMark website, it outputs what I was expecting:

<h1>Foo</h1>

If you disable the autolink extension, the anchor is not generated:

app(dev)> Commonmarker.to_html("# Foo", options: { extension: { autolink: false } })
=> "<h1>Foo</h1>\n"

However, autolinking is something I do want. Is there a way to disable these heading anchor from being generated, while retaining the standard autolink functionality?

Thanks in advance!

@gjtorikian
Copy link
Owner

Could you try options: { extension: { header_ids: nil } } ?

@tysongach
Copy link
Author

@gjtorikian Yep, that removed the anchors for me. Thank you! I wonder if that should be the default?

@gjtorikian
Copy link
Owner

Yes, I’m having a big think about defaults at the moment. Actually #315 is a more general bug around the issue you faced with autolink: false. Apparently, the defaults aren’t getting merged correctly, and no one has noticed until now!

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

No branches or pull requests

2 participants