Update MD041/first-line-heading to add an allow_preamble parameter (fixes #1416).

This commit is contained in:
David Anson 2025-03-22 16:15:59 -07:00
parent c061888937
commit 62dc79864d
17 changed files with 538 additions and 163 deletions

View file

@ -0,0 +1,22 @@
Text {MD041}
<!-- Comment -->
Text
<p>HTML</p>
Text
- List item
# Heading
Text
<!-- markdownlint-configure-file {
"first-line-heading": {
"allow_preamble": false
},
"no-inline-html": false
} -->

View file

@ -0,0 +1,22 @@
Text
<!-- Comment -->
Text
<p>HTML</p>
Text
- List item
<h1>Heading</h1>
Text
<!-- markdownlint-configure-file {
"first-line-heading": {
"allow_preamble": true
},
"no-inline-html": false
} -->

View file

@ -0,0 +1,22 @@
Text
<!-- Comment -->
Text
<p>HTML</p>
Text
- List item
## Heading {MD041}
Text
<!-- markdownlint-configure-file {
"first-line-heading": {
"allow_preamble": true
},
"no-inline-html": false
} -->

View file

@ -0,0 +1,22 @@
Text
<!-- Comment -->
Text
<p>HTML</p>
Text
- List item
# Heading
Text
<!-- markdownlint-configure-file {
"first-line-heading": {
"allow_preamble": true
},
"no-inline-html": false
} -->

View file

@ -907,7 +907,7 @@ test("readme", async(t) => {
});
test("validateJsonUsingConfigSchemaStrict", async(t) => {
t.plan(192);
t.plan(196);
// @ts-ignore
const ajv = new Ajv(ajvOptions);
const validateSchemaStrict = ajv.compile(configSchemaStrict);

View file

@ -13752,6 +13752,160 @@ Generated by [AVA](https://avajs.dev).
`,
}
## first-line-heading-allow-preamble-false.md
> Snapshot 1
{
errors: [
{
errorContext: 'Text {MD041}',
errorDetail: null,
errorRange: null,
fixInfo: null,
lineNumber: 1,
ruleDescription: 'First line in a file should be a top-level heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md041.md',
ruleNames: [
'MD041',
'first-line-heading',
'first-line-h1',
],
},
],
fixed: `Text {MD041}␊
<!-- Comment -->
Text␊
<p>HTML</p>
Text␊
- List item␊
# Heading␊
Text␊
<!-- markdownlint-configure-file {␊
"first-line-heading": {␊
"allow_preamble": false␊
},␊
"no-inline-html": false␊
} -->␊
`,
}
## first-line-heading-allow-preamble-h1.md
> Snapshot 1
{
errors: [],
fixed: `Text␊
<!-- Comment -->
Text␊
<p>HTML</p>
Text␊
- List item␊
<h1>Heading</h1>
Text␊
<!-- markdownlint-configure-file {␊
"first-line-heading": {␊
"allow_preamble": true␊
},␊
"no-inline-html": false␊
} -->␊
`,
}
## first-line-heading-allow-preamble-violation.md
> Snapshot 1
{
errors: [
{
errorContext: '## Heading {MD041}',
errorDetail: null,
errorRange: null,
fixInfo: null,
lineNumber: 13,
ruleDescription: 'First line in a file should be a top-level heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md041.md',
ruleNames: [
'MD041',
'first-line-heading',
'first-line-h1',
],
},
],
fixed: `Text␊
<!-- Comment -->
Text␊
<p>HTML</p>
Text␊
- List item␊
## Heading {MD041}␊
Text␊
<!-- markdownlint-configure-file {␊
"first-line-heading": {␊
"allow_preamble": true␊
},␊
"no-inline-html": false␊
} -->␊
`,
}
## first-line-heading-allow-preamble.md
> Snapshot 1
{
errors: [],
fixed: `Text␊
<!-- Comment -->
Text␊
<p>HTML</p>
Text␊
- List item␊
# Heading␊
Text␊
<!-- markdownlint-configure-file {␊
"first-line-heading": {␊
"allow_preamble": true␊
},␊
"no-inline-html": false␊
} -->␊
`,
}
## first_heading_bad_atx.md
> Snapshot 1