Mismatch in case when using anchors #333

Closed
opened 2026-01-29 14:34:01 +00:00 by claunia · 4 comments
Owner

Originally created by @Skotasma on GitHub (Oct 9, 2019).

First of all thanks for the good work!
Maybe I'm doing it wrong, but my anchors don't work:
I'm simply using the advanced extensions to generate HTML from md.
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();

What happens is, that in the link the name is preserved, but in the id the name is lower case.
As a result anchors don't work.
Example:

[Formatting](#Formatting)
[...]
# Formatting

Generates

<a href="#Formatting">Formatting</a>
[...]
<h1 id="formatting">Formatting</h1>

Thanks!

Originally created by @Skotasma on GitHub (Oct 9, 2019). First of all thanks for the good work! Maybe I'm doing it wrong, but my anchors don't work: I'm simply using the advanced extensions to generate HTML from md. var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); What happens is, that in the link the name is preserved, but in the id the name is lower case. As a result anchors don't work. Example: ``` [Formatting](#Formatting) [...] # Formatting ``` Generates ``` <a href="#Formatting">Formatting</a> [...] <h1 id="formatting">Formatting</h1> ``` Thanks!
Author
Owner

@MihaZupan commented on GitHub (Oct 9, 2019):

There seems to be a consensus among different Markdown parsers as to how the heading id is generated. In other words, making the identifier lower-case is by design.

The solution is to use the lower-case identifier when linking to the heading.

[Formatting](#formatting)

# Formatting
@MihaZupan commented on GitHub (Oct 9, 2019): There seems to be a consensus among different Markdown parsers as to how the heading id is generated. In other words, making the identifier lower-case is by design. The solution is to use the lower-case identifier when linking to the heading. ```md [Formatting](#formatting) # Formatting ```
Author
Owner

@xoofx commented on GitHub (Oct 9, 2019):

Yeah. there are several rules, including replacing space by - or collapsing non alpha-numeric characters...etc.

So basically by design. Not sure it is worth adding a different rule, while these links would not work at all on GitHub for example (or even Gitlab), so better to use the common accepted rule

Closing this issue. If you really want this feature, you can try a PR to bring it to the AutoIdentifier extension.

@xoofx commented on GitHub (Oct 9, 2019): Yeah. there are several rules, including replacing space by `-` or collapsing non alpha-numeric characters...etc. - [Default rule](https://github.com/lunet-io/markdig/blob/c8186709198074da4528838eb78c32c704c1789a/src/Markdig/Helpers/LinkHelper.cs#L20-L96) is following what I think Pandoc is doing. - [Gfm rule](https://github.com/lunet-io/markdig/blob/c8186709198074da4528838eb78c32c704c1789a/src/Markdig/Helpers/LinkHelper.cs#L98-L113) So basically by design. Not sure it is worth adding a different rule, while these links would not work at all on GitHub for example (or even Gitlab), so better to use the common accepted rule Closing this issue. If you really want this feature, you can try a PR to bring it to the AutoIdentifier extension.
Author
Owner

@Skotasma commented on GitHub (Oct 10, 2019):

Thanks for the quick reply!
As this is not really usable, I'll hope I get people to use this format for anchors:

[Formatting](#anchor1)
[...]
# <a id="anchor1"></a> Formatting

This works and you don't need to guess the correct text to use for the link, esp. thinking of more complicated headings spaces, numbers, special characters etc.

@Skotasma commented on GitHub (Oct 10, 2019): Thanks for the quick reply! As this is not really usable, I'll hope I get people to use this format for anchors: ``` [Formatting](#anchor1) [...] # <a id="anchor1"></a> Formatting ``` This works and you don't need to guess the correct text to use for the link, esp. thinking of more complicated headings spaces, numbers, special characters etc.
Author
Owner

@xoofx commented on GitHub (Oct 10, 2019):

You can also avoid explicit anchors in that case:

[Formatting]

# Formatting

Or in this documentation for example the entire table of content was generated using the mdtoc tool inside markdig repo. It was really fine for this case.

Otherwise, if you want an absolute control on the anchors, yes, there is no other way than using direct inline HTML

@xoofx commented on GitHub (Oct 10, 2019): You can also [avoid explicit anchors](https://babelmark.github.io/?text=%5BFormatting%5D%0A%0A%23+Formatting) in that case: ``` [Formatting] # Formatting ``` Or in [this documentation for example](https://github.com/lunet-io/scriban/blob/master/doc/runtime.md) the entire table of content was generated using the mdtoc tool inside markdig repo. It was really fine for this case. Otherwise, if you want an absolute control on the anchors, yes, there is no other way than using direct inline HTML
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#333