Reimplement MD024/no-duplicate-heading using micromark tokens.

This commit is contained in:
David Anson 2024-06-19 21:05:31 -07:00
parent b1b16dabec
commit 96354678dc
6 changed files with 77 additions and 49 deletions

View file

@ -3,7 +3,7 @@
"use strict";
const { addErrorContext, frontMatterHasTitle } = require("../helpers");
const { filterByTypes, getHeadingLevel } = require("../helpers/micromark.cjs");
const { filterByTypes, getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
@ -28,14 +28,7 @@ module.exports = {
const headingLevel = getHeadingLevel(heading);
if (headingLevel === level) {
if (hasTopLevelHeading || foundFrontMatterTitle) {
const headingTexts = filterByTypes(
heading.children,
[ "atxHeadingText", "setextHeadingText" ]
);
const headingText = headingTexts.
map((token) => token.text).
join(" ").
replace(/[\r\n]+/g, " ");
const headingText = getHeadingText(heading);
addErrorContext(
onError,
heading.startLine,