[GH-ISSUE #538] MD051 should support arbitrary id attributes, not just <a> tags #440

Closed
opened 2026-03-03 01:26:56 +03:00 by kerem · 1 comment
Owner

Originally created by @MarkLodato on GitHub (Jul 26, 2022).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/538

MD051 currently only checks <a> tags for id="..." attributes, but this requirement seems arbitrary. Any HTML element may have an id attribute to define an anchor.

It seems like this can be easily fixed by removing the check for a tags on line 58.

In my case, I have a table and use id attributes to link to specfic rows of the table:

# Example

<table>
<tr id="foo"><td>Foo<td>Foo is good
<tr id="bar"><td>Bar<td>Bar is also good
</table>

I like [foo](#foo) and [bar](#bar).
$ npx markdownlint test.md
test.md:8:8 MD051/link-fragments Link fragments should be valid [Context: "[foo](#foo) and [bar](#bar)"]
test.md:8:8 MD051/link-fragments Link fragments should be valid [Context: "[foo](#foo)"]

Would you be willing to accept a PR that fixes this, or is there some other reason why only a tags are accepted?

Originally created by @MarkLodato on GitHub (Jul 26, 2022). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/538 MD051 currently only checks `<a>` tags for `id="..."` attributes, but this requirement seems arbitrary. Any HTML element may have an `id` attribute to define an anchor. It seems like this can be easily fixed by removing the check for `a` tags on [line 58](https://github.com/DavidAnson/markdownlint/blob/cba2ca0dbdc8f11e4b97c054380ffd52bb7aae19/lib/md051.js#L58). In my case, I have a table and use `id` attributes to link to specfic rows of the table: ```markdown # Example <table> <tr id="foo"><td>Foo<td>Foo is good <tr id="bar"><td>Bar<td>Bar is also good </table> I like [foo](#foo) and [bar](#bar). ``` ``` $ npx markdownlint test.md test.md:8:8 MD051/link-fragments Link fragments should be valid [Context: "[foo](#foo) and [bar](#bar)"] test.md:8:8 MD051/link-fragments Link fragments should be valid [Context: "[foo](#foo)"] ``` Would you be willing to accept a PR that fixes this, or is there some other reason why only `a` tags are accepted?
kerem 2026-03-03 01:26:56 +03:00
Author
Owner

@DavidAnson commented on GitHub (Jul 26, 2022):

Yes, I would accept a PR for this! Please read the CONTRIBUTING guide first. Thank you!

<!-- gh-comment-id:1195689672 --> @DavidAnson commented on GitHub (Jul 26, 2022): Yes, I would accept a PR for this! Please read the CONTRIBUTING guide first. Thank you!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#440
No description provided.