mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
37
lib/md025.mjs
Normal file
37
lib/md025.mjs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// @ts-check
|
||||
|
||||
import { addErrorContext, frontMatterHasTitle } from "../helpers/helpers.cjs";
|
||||
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
|
||||
import { filterByTypesCached } from "./cache.mjs";
|
||||
|
||||
/** @type {import("./markdownlint.mjs").Rule} */
|
||||
export default {
|
||||
"names": [ "MD025", "single-title", "single-h1" ],
|
||||
"description": "Multiple top-level headings in the same document",
|
||||
"tags": [ "headings" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD025(params, onError) {
|
||||
const level = Number(params.config.level || 1);
|
||||
const foundFrontMatterTitle =
|
||||
frontMatterHasTitle(
|
||||
params.frontMatterLines,
|
||||
params.config.front_matter_title
|
||||
);
|
||||
let hasTopLevelHeading = false;
|
||||
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
||||
const headingLevel = getHeadingLevel(heading);
|
||||
if (headingLevel === level) {
|
||||
if (hasTopLevelHeading || foundFrontMatterTitle) {
|
||||
const headingText = getHeadingText(heading);
|
||||
addErrorContext(
|
||||
onError,
|
||||
heading.startLine,
|
||||
headingText
|
||||
);
|
||||
} else if (heading.startLine === 1) {
|
||||
hasTopLevelHeading = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue