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
42
lib/md036.mjs
Normal file
42
lib/md036.mjs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// @ts-check
|
||||
|
||||
import { addErrorContext, allPunctuation } from "../helpers/helpers.cjs";
|
||||
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
||||
import { filterByTypesCached } from "./cache.mjs";
|
||||
|
||||
/** @typedef {import("../helpers/micromark-helpers.cjs").TokenType} TokenType */
|
||||
/** @type {TokenType[][]} */
|
||||
const emphasisTypes = [
|
||||
[ "emphasis", "emphasisText" ],
|
||||
[ "strong", "strongText" ]
|
||||
];
|
||||
|
||||
/** @type {import("./markdownlint.mjs").Rule} */
|
||||
export default {
|
||||
"names": [ "MD036", "no-emphasis-as-heading" ],
|
||||
"description": "Emphasis used instead of a heading",
|
||||
"tags": [ "headings", "emphasis" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD036(params, onError) {
|
||||
let punctuation = params.config.punctuation;
|
||||
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
|
||||
const punctuationRe = new RegExp("[" + punctuation + "]$");
|
||||
const paragraphTokens =
|
||||
filterByTypesCached([ "paragraph" ])
|
||||
.filter((token) =>
|
||||
(token.parent?.type === "content") && !token.parent?.parent && (token.children.length === 1)
|
||||
);
|
||||
for (const emphasisType of emphasisTypes) {
|
||||
const textTokens = getDescendantsByType(paragraphTokens, emphasisType);
|
||||
for (const textToken of textTokens) {
|
||||
if (
|
||||
(textToken.children.length === 1) &&
|
||||
(textToken.children[0].type === "data") &&
|
||||
!punctuationRe.test(textToken.text)
|
||||
) {
|
||||
addErrorContext(onError, textToken.startLine, textToken.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue