mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-02-28 07:44:07 +01:00
Update MD001/heading-increment to support front matter title as the first heading of the page.
This commit is contained in:
parent
a366f80873
commit
1b6839bff0
21 changed files with 317 additions and 16 deletions
18
lib/configuration-strict.d.ts
vendored
18
lib/configuration-strict.d.ts
vendored
|
|
@ -21,11 +21,25 @@ export interface ConfigurationStrict {
|
|||
/**
|
||||
* MD001/heading-increment : Heading levels should only increment by one level at a time : https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md001.md
|
||||
*/
|
||||
MD001?: boolean;
|
||||
MD001?:
|
||||
| boolean
|
||||
| {
|
||||
/**
|
||||
* RegExp for matching title in front matter
|
||||
*/
|
||||
front_matter_title?: string;
|
||||
};
|
||||
/**
|
||||
* MD001/heading-increment : Heading levels should only increment by one level at a time : https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md001.md
|
||||
*/
|
||||
"heading-increment"?: boolean;
|
||||
"heading-increment"?:
|
||||
| boolean
|
||||
| {
|
||||
/**
|
||||
* RegExp for matching title in front matter
|
||||
*/
|
||||
front_matter_title?: string;
|
||||
};
|
||||
/**
|
||||
* MD003/heading-style : Heading style : https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md003.md
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// @ts-check
|
||||
|
||||
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
||||
import { addErrorDetailIf, frontMatterHasTitle } from "../helpers/helpers.cjs";
|
||||
import { getHeadingLevel } from "../helpers/micromark-helpers.cjs";
|
||||
import { filterByTypesCached } from "./cache.mjs";
|
||||
|
||||
|
|
@ -11,7 +11,11 @@ export default {
|
|||
"tags": [ "headings" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD001(params, onError) {
|
||||
let prevLevel = Number.MAX_SAFE_INTEGER;
|
||||
const hasTitle = frontMatterHasTitle(
|
||||
params.frontMatterLines,
|
||||
params.config.front_matter_title
|
||||
);
|
||||
let prevLevel = hasTitle ? 1 : Number.MAX_SAFE_INTEGER;
|
||||
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
||||
const level = getHeadingLevel(heading);
|
||||
if (level > prevLevel) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue