Initial implementation of MD051/valid-link-fragments (refs #253, closes #495).

This commit is contained in:
Divlo 2022-01-26 00:21:08 +01:00 committed by David Anson
parent 62f5c85238
commit 33ee1cd85e
13 changed files with 250 additions and 24 deletions

View file

@ -56,7 +56,8 @@ Aliases: first-heading-h1, first-header-h1
Parameters: level (number; default 1)
> Note: *MD002 has been deprecated and is disabled by default.*
> [MD041/first-line-heading](#md041) offers an improved implementation.
> [MD041/first-line-heading](#md041---first-line-in-a-file-should-be-a-top-level-heading)
offers an improved implementation.
This rule is intended to ensure document headings start at the top level and
is triggered when the first heading in the document isn't an h1 heading:
@ -783,7 +784,8 @@ The `lines_above` and `lines_below` parameters can be used to specify a differen
number of blank lines (including 0) above or below each heading.
Note: If `lines_above` or `lines_below` are configured to require more than one
blank line, [MD012/no-multiple-blanks](#md012) should also be customized.
blank line, [MD012/no-multiple-blanks](#md012---multiple-consecutive-blank-lines)
should also be customized.
Rationale: Aside from aesthetic reasons, some parsers, including `kramdown`, will
not parse headings that don't have a blank line before, and will parse them as
@ -1984,3 +1986,26 @@ The configured strong style can be a specific symbol to use ("asterisk",
"underscore"), or can require that usage be consistent within the document.
Rationale: Consistent formatting makes it easier to understand a document.
<a name="md051"></a>
## MD051 - Link fragments should be valid
Tags: links
Aliases: valid-link-fragments
This rule is triggered if a link fragment does not correspond to a
heading within the document:
```markdown
# Title
[Link](#invalid-fragment)
```
To fix this issue, ensure that the heading exists,
here you could replace `#invalid-fragment` by `#title`.
It's not part of the CommonMark specification,
for example [GitHub turn headings into links](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#section-links).