mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Reimplement MD024/no-duplicate-heading using micromark tokens.
This commit is contained in:
parent
b1b16dabec
commit
96354678dc
6 changed files with 77 additions and 49 deletions
11
lib/md025.js
11
lib/md025.js
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue