Update MD041/first-line-heading to recognize HTML headings (fixes #366).

This commit is contained in:
David Anson 2021-01-31 15:48:00 -08:00
parent c7d2416f95
commit 1d042aa3fd
7 changed files with 69 additions and 4 deletions

View file

@ -17,11 +17,22 @@ module.exports = {
params.config.front_matter_title
);
if (!foundFrontMatterTitle) {
const htmlHeadingRe = new RegExp(`^<h${level}[ />]`, "i");
params.tokens.every((token) => {
let isError = false;
if (token.type === "html_block") {
return true;
if (token.content.startsWith("<!--")) {
// Ignore leading HTML comments
return true;
} else if (!htmlHeadingRe.test(token.content)) {
// Something other than an HTML heading
isError = true;
}
} else if ((token.type !== "heading_open") || (token.tag !== tag)) {
// Something other than a Markdown heading
isError = true;
}
if ((token.type !== "heading_open") || (token.tag !== tag)) {
if (isError) {
addErrorContext(onError, token.lineNumber, token.line);
}
return false;