Update MD043/required-headings to support "?" meaning "exactly one unspecified heading" (fixes #475).

This commit is contained in:
David Anson 2025-03-10 21:57:28 -07:00
parent 06b60b7372
commit 5749c8dcf7
15 changed files with 297 additions and 18 deletions

View file

@ -1767,7 +1767,7 @@ structure for a set of files.
To require exactly the following structure:
```markdown
# Head
# Heading
## Item
### Detail
```
@ -1776,7 +1776,7 @@ Set the `headings` parameter to:
```json
[
"# Head",
"# Heading",
"## Item",
"### Detail"
]
@ -1785,7 +1785,7 @@ Set the `headings` parameter to:
To allow optional headings as with the following structure:
```markdown
# Head
# Heading
## Item
### Detail (optional)
## Foot
@ -1798,7 +1798,7 @@ special value `"+"` meaning "one or more unspecified headings" and set the
```json
[
"# Head",
"# Heading",
"## Item",
"*",
"## Foot",
@ -1806,6 +1806,24 @@ special value `"+"` meaning "one or more unspecified headings" and set the
]
```
To allow a single required heading to vary as with a project name:
```markdown
# Project Name
## Description
## Examples
```
Use the special value `"?"` meaning "exactly one unspecified heading":
```json
[
"?",
"## Description",
"## Examples"
]
```
When an error is detected, this rule outputs the line number of the first
problematic heading (otherwise, it outputs the last line number of the file).

View file

@ -16,7 +16,7 @@ structure for a set of files.
To require exactly the following structure:
```markdown
# Head
# Heading
## Item
### Detail
```
@ -25,7 +25,7 @@ Set the `headings` parameter to:
```json
[
"# Head",
"# Heading",
"## Item",
"### Detail"
]
@ -34,7 +34,7 @@ Set the `headings` parameter to:
To allow optional headings as with the following structure:
```markdown
# Head
# Heading
## Item
### Detail (optional)
## Foot
@ -47,7 +47,7 @@ special value `"+"` meaning "one or more unspecified headings" and set the
```json
[
"# Head",
"# Heading",
"## Item",
"*",
"## Foot",
@ -55,6 +55,24 @@ special value `"+"` meaning "one or more unspecified headings" and set the
]
```
To allow a single required heading to vary as with a project name:
```markdown
# Project Name
## Description
## Examples
```
Use the special value `"?"` meaning "exactly one unspecified heading":
```json
[
"?",
"## Description",
"## Examples"
]
```
When an error is detected, this rule outputs the line number of the first
problematic heading (otherwise, it outputs the last line number of the file).