Skip to content

Commit be8ab9c

Browse files
committed
wip
1 parent d54312a commit be8ab9c

16 files changed

Lines changed: 320 additions & 20 deletions

‎doc-build/md024.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If the parameter `siblings_only` is set to `true`, duplication is allowed for
1919
headings with different parents (as is common in changelogs):
2020

2121
```markdown
22-
# Change log
22+
# Changelog
2323

2424
## 1.0.0
2525

‎doc-build/md043.md‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ To allow optional headings as with the following structure:
2626
# Heading
2727
## Item
2828
### Detail (optional)
29+
### Example (optional)
2930
## Foot
3031
### Notes (optional)
3132
```
@@ -40,19 +41,30 @@ special value `"+"` meaning "one or more unspecified headings" and set the
4041
"## Item",
4142
"*",
4243
"## Foot",
43-
"*"
44+
"+"
4445
]
4546
```
4647

47-
To allow a single required heading to vary as with a project name:
48+
To allow a single required heading to vary (as with a project name):
4849

4950
```markdown
5051
# Project Name
5152
## Description
5253
## Examples
5354
```
5455

55-
Use the special value `"?"` meaning "exactly one unspecified heading":
56+
Use the syntax `"#"`, `"##"`, etc. to allow any text at the specified heading
57+
level:
58+
59+
```json
60+
[
61+
"#",
62+
"## Description",
63+
"## Examples"
64+
]
65+
```
66+
67+
Or use the special value `"?"` to allow one unspecified heading at any level:
5668

5769
```json
5870
[

‎doc/Rules.md‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ If the parameter `siblings_only` is set to `true`, duplication is allowed for
859859
headings with different parents (as is common in changelogs):
860860

861861
```markdown
862-
# Change log
862+
# Changelog
863863

864864
## 1.0.0
865865

@@ -1871,6 +1871,7 @@ To allow optional headings as with the following structure:
18711871
# Heading
18721872
## Item
18731873
### Detail (optional)
1874+
### Example (optional)
18741875
## Foot
18751876
### Notes (optional)
18761877
```
@@ -1885,19 +1886,30 @@ special value `"+"` meaning "one or more unspecified headings" and set the
18851886
"## Item",
18861887
"*",
18871888
"## Foot",
1888-
"*"
1889+
"+"
18891890
]
18901891
```
18911892

1892-
To allow a single required heading to vary as with a project name:
1893+
To allow a single required heading to vary (as with a project name):
18931894

18941895
```markdown
18951896
# Project Name
18961897
## Description
18971898
## Examples
18981899
```
18991900

1900-
Use the special value `"?"` meaning "exactly one unspecified heading":
1901+
Use the syntax `"#"`, `"##"`, etc. to allow any text at the specified heading
1902+
level:
1903+
1904+
```json
1905+
[
1906+
"#",
1907+
"## Description",
1908+
"## Examples"
1909+
]
1910+
```
1911+
1912+
Or use the special value `"?"` to allow one unspecified heading at any level:
19011913

19021914
```json
19031915
[

‎doc/md024.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If the parameter `siblings_only` is set to `true`, duplication is allowed for
2929
headings with different parents (as is common in changelogs):
3030

3131
```markdown
32-
# Change log
32+
# Changelog
3333

3434
## 1.0.0
3535

‎doc/md043.md‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ To allow optional headings as with the following structure:
3737
# Heading
3838
## Item
3939
### Detail (optional)
40+
### Example (optional)
4041
## Foot
4142
### Notes (optional)
4243
```
@@ -51,19 +52,30 @@ special value `"+"` meaning "one or more unspecified headings" and set the
5152
"## Item",
5253
"*",
5354
"## Foot",
54-
"*"
55+
"+"
5556
]
5657
```
5758

58-
To allow a single required heading to vary as with a project name:
59+
To allow a single required heading to vary (as with a project name):
5960

6061
```markdown
6162
# Project Name
6263
## Description
6364
## Examples
6465
```
6566

66-
Use the special value `"?"` meaning "exactly one unspecified heading":
67+
Use the syntax `"#"`, `"##"`, etc. to allow any text at the specified heading
68+
level:
69+
70+
```json
71+
[
72+
"#",
73+
"## Description",
74+
"## Examples"
75+
]
76+
```
77+
78+
Or use the special value `"?"` to allow one unspecified heading at any level:
6779

6880
```json
6981
[

‎helpers/micromark-helpers.cjs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ function getHeadingText(heading) {
218218
.flatMap((descendant) => descendant.children.filter((child) => child.type !== "htmlText"))
219219
.map((data) => data.text)
220220
.join("")
221-
.replace(newlineRe, " ");
221+
.replace(newlineRe, " ")
222+
.trim();
222223
}
223224

224225
/**

‎lib/md043.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { addErrorContext, addErrorDetailIf } from "../helpers/helpers.cjs";
44
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
55
import { filterByTypesCached } from "./cache.mjs";
66

7+
const headingLevelWithAnyTextRe = /^#{1,6}$/;
8+
79
/** @type {import("markdownlint").Rule} */
810
export default {
911
"names": [ "MD043", "required-headings" ],
@@ -40,7 +42,10 @@ export default {
4042
matchAny = true;
4143
} else if (expected === "?") {
4244
// Allow current, match next
43-
} else if (handleCase(expected) === handleCase(actual)) {
45+
} else if (
46+
(handleCase(expected) === handleCase(actual)) ||
47+
(headingLevelWithAnyTextRe.test(expected) && (headingLevel === expected.length))
48+
) {
4449
matchAny = false;
4550
} else if (matchAny) {
4651
i--;

‎schema/build-config-schema.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ for (const rule of rules) {
453453
"type": "array",
454454
"items": {
455455
"type": "string",
456-
"pattern": "^(\\*|\\+|\\?|#{1,6}\\s+\\S.*)$"
456+
"pattern": "^(\\*|\\+|\\?|#{1,6}(?:|\\s+\\S.*))$"
457457
},
458458
"default": []
459459
};

‎schema/markdownlint-config-schema-strict.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,7 +3262,7 @@
32623262
"type": "array",
32633263
"items": {
32643264
"type": "string",
3265-
"pattern": "^(\\*|\\+|\\?|#{1,6}\\s+\\S.*)$"
3265+
"pattern": "^(\\*|\\+|\\?|#{1,6}(?:|\\s+\\S.*))$"
32663266
},
32673267
"default": []
32683268
},
@@ -3311,7 +3311,7 @@
33113311
"type": "array",
33123312
"items": {
33133313
"type": "string",
3314-
"pattern": "^(\\*|\\+|\\?|#{1,6}\\s+\\S.*)$"
3314+
"pattern": "^(\\*|\\+|\\?|#{1,6}(?:|\\s+\\S.*))$"
33153315
},
33163316
"default": []
33173317
},

‎schema/markdownlint-config-schema.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,7 +3262,7 @@
32623262
"type": "array",
32633263
"items": {
32643264
"type": "string",
3265-
"pattern": "^(\\*|\\+|\\?|#{1,6}\\s+\\S.*)$"
3265+
"pattern": "^(\\*|\\+|\\?|#{1,6}(?:|\\s+\\S.*))$"
32663266
},
32673267
"default": []
32683268
},
@@ -3311,7 +3311,7 @@
33113311
"type": "array",
33123312
"items": {
33133313
"type": "string",
3314-
"pattern": "^(\\*|\\+|\\?|#{1,6}\\s+\\S.*)$"
3314+
"pattern": "^(\\*|\\+|\\?|#{1,6}(?:|\\s+\\S.*))$"
33153315
},
33163316
"default": []
33173317
},

0 commit comments

Comments
 (0)