Reimplement MD041/first-line-heading/first-line-h1 using micromark tokens.

This commit is contained in:
David Anson 2024-03-18 20:48:22 -07:00
parent 0f5e65abd4
commit a83e2d8a09
4 changed files with 94 additions and 80 deletions

View file

@ -309,11 +309,19 @@ function getHeadingLevel(heading) {
return level;
}
/**
* HTML tag information.
*
* @typedef {Object} HtmlTagInfo
* @property {boolean} close True iff close tag.
* @property {string} name Tag name.
*/
/**
* Gets information about the tag in an HTML token.
*
* @param {Token} token Micromark token.
* @returns {Object | null} HTML tag information.
* @returns {HtmlTagInfo | null} HTML tag information.
*/
function getHtmlTagInfo(token) {
const htmlTagNameRe = /^<([^!>][^/\s>]*)/;
@ -405,6 +413,21 @@ function tokenIfType(token, type) {
return (token && (token.type === type)) ? token : null;
}
/**
* Set containing token types that do not contain content.
*
* @type {Set<TokenType>}
*/
const nonContentTokens = new Set([
"blockQuoteMarker",
"blockQuotePrefix",
"blockQuotePrefixWhitespace",
"lineEnding",
"lineEndingBlank",
"linePrefix",
"listItemIndent"
]);
module.exports = {
"parse": micromarkParse,
filterByPredicate,
@ -415,6 +438,8 @@ module.exports = {
getTokenParentOfType,
getTokenTextByType,
inHtmlFlow,
isHtmlFlowComment,
matchAndGetTokensByType,
nonContentTokens,
tokenIfType
};