theoludwig / markdownlint-rule-relative-links

Custom rule for markdownlint to validate relative links.
https://www.npmjs.com/package/markdownlint-rule-relative-links
MIT License
8 stars 1 forks source link

[Feature] Validate anchors #2

Closed rmartine-ias closed 1 year ago

rmartine-ias commented 1 year ago

Description

It would be very useful to validate that anchors exist:

some.md:

[Link](other.md#existing)
[Link](other.md#not-existing)

other.md:

# Existing

This would give an error that other.md#not-existing is not a valid link.

This would be useful, because I moved a section from one file to another, and now I don't know what links I've broken. Similarly, I would like to know when renaming a header invalidates a link.

Describe the solution you'd like

A piece of config to specify whether to opt-out of this behavior, with it being on by default.

Describe alternatives you've considered

I considered switching to markdownlint-link-check, but they don't do it either.

The other alternative would be the current behavior, not linting for dead link fragments.

theoludwig commented 1 year ago

Hello! :wave: @rmartine-ias

Thanks for your report. Validating anchors/fragments in other files is a great idea! markdownlint already validate fragments with the MD051 - link-fragments rule, but is only working for titles in the same file. Could be great to make it work with links to other files, with a similar logic for converting headings/titles to fragments as the MD051 rule in markdownlint (https://github.com/DavidAnson/markdownlint/blob/d01180ec5a014083ee9d574b693a8d7fbc1e566d/lib/md051.js#L19).

Feel free to open PRs to implement this feature, would appreciate it. :smile:

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

rmartine-ias commented 1 year ago

Thank you so much for implementing this! Was unable to get around to doing it myself, this will be super useful.