@@ -1559,8 +1559,8 @@ function inHtmlFlow(token) {
1559
1559
* Determines a list of Micromark tokens matches and returns a subset.
1560
1560
*
1561
1561
* @param {Token[] } tokens Micromark tokens.
1562
- * @param {string [] } matchTypes Types to match.
1563
- * @param {string [] } [resultTypes] Types to return.
1562
+ * @param {TokenType [] } matchTypes Types to match.
1563
+ * @param {TokenType [] } [resultTypes] Types to return.
1564
1564
* @returns {Token[] | null } Matching tokens.
1565
1565
*/
1566
1566
function matchAndGetTokensByType ( tokens , matchTypes , resultTypes ) {
@@ -5315,57 +5315,48 @@ module.exports = {
5315
5315
5316
5316
5317
5317
const { addErrorContext, allPunctuation } = __webpack_require__ ( /*! ../helpers */ "../helpers/helpers.js" ) ;
5318
+ const { filterByTypes, matchAndGetTokensByType } = __webpack_require__ ( /*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs" ) ;
5319
+
5320
+ /** @typedef {import("../helpers/micromark.cjs").TokenType } TokenType */
5321
+ /** @type {Map<TokenType, TokenType[]> } */
5322
+ const emphasisAndChildrenTypes = new Map ( [
5323
+ [ "emphasis" , [ "emphasisSequence" , "emphasisText" , "emphasisSequence" ] ] ,
5324
+ [ "strong" , [ "strongSequence" , "strongText" , "strongSequence" ] ]
5325
+ ] ) ;
5318
5326
5319
5327
// eslint-disable-next-line jsdoc/valid-types
5320
5328
/** @type import("./markdownlint").Rule */
5321
5329
module . exports = {
5322
5330
"names" : [ "MD036" , "no-emphasis-as-heading" ] ,
5323
5331
"description" : "Emphasis used instead of a heading" ,
5324
5332
"tags" : [ "headings" , "emphasis" ] ,
5325
- "parser" : "markdownit " ,
5333
+ "parser" : "micromark " ,
5326
5334
"function" : function MD036 ( params , onError ) {
5327
5335
let punctuation = params . config . punctuation ;
5328
- punctuation =
5329
- String ( ( punctuation === undefined ) ? allPunctuation : punctuation ) ;
5330
- const re = new RegExp ( "[" + punctuation + "]$" ) ;
5331
- // eslint-disable-next-line jsdoc/require-jsdoc
5332
- function base ( token ) {
5333
- if ( token . type === "paragraph_open" ) {
5334
- return function inParagraph ( t ) {
5335
- // Always paragraph_open/inline/paragraph_close,
5336
- const children = t . children . filter ( function notEmptyText ( child ) {
5337
- return ( child . type !== "text" ) || ( child . content !== "" ) ;
5338
- } ) ;
5339
- if ( ( children . length === 3 ) &&
5340
- ( ( children [ 0 ] . type === "strong_open" ) ||
5341
- ( children [ 0 ] . type === "em_open" ) ) &&
5342
- ( children [ 1 ] . type === "text" ) &&
5343
- ! re . test ( children [ 1 ] . content ) ) {
5344
- addErrorContext ( onError , t . lineNumber ,
5345
- children [ 1 ] . content ) ;
5346
- }
5347
- return base ;
5348
- } ;
5349
- } else if ( token . type === "blockquote_open" ) {
5350
- return function inBlockquote ( t ) {
5351
- if ( t . type !== "blockquote_close" ) {
5352
- return inBlockquote ;
5353
- }
5354
- return base ;
5355
- } ;
5356
- } else if ( token . type === "list_item_open" ) {
5357
- return function inListItem ( t ) {
5358
- if ( t . type !== "list_item_close" ) {
5359
- return inListItem ;
5336
+ punctuation = String ( ( punctuation === undefined ) ? allPunctuation : punctuation ) ;
5337
+ const punctuationRe = new RegExp ( "[" + punctuation + "]$" ) ;
5338
+ const paragraphTokens =
5339
+ filterByTypes ( params . parsers . micromark . tokens , [ "paragraph" ] ) .
5340
+ filter ( ( token ) =>
5341
+ ( token . parent ?. type === "content" ) && ! token . parent ?. parent && ( token . children . length === 1 )
5342
+ ) ;
5343
+ for ( const paragraphToken of paragraphTokens ) {
5344
+ const childToken = paragraphToken . children [ 0 ] ;
5345
+ for ( const [ emphasisType , emphasisChildrenTypes ] of emphasisAndChildrenTypes ) {
5346
+ if ( childToken . type === emphasisType ) {
5347
+ const matchingTokens = matchAndGetTokensByType ( childToken . children , emphasisChildrenTypes ) ;
5348
+ if ( matchingTokens ) {
5349
+ const textToken = matchingTokens [ 1 ] ;
5350
+ if (
5351
+ ( textToken . children . length === 1 ) &&
5352
+ ( textToken . children [ 0 ] . type === "data" ) &&
5353
+ ! punctuationRe . test ( textToken . text )
5354
+ ) {
5355
+ addErrorContext ( onError , textToken . startLine , textToken . text ) ;
5356
+ }
5360
5357
}
5361
- return base ;
5362
- } ;
5358
+ }
5363
5359
}
5364
- return base ;
5365
- }
5366
- let state = base ;
5367
- for ( const token of params . parsers . markdownit . tokens ) {
5368
- state = state ( token ) ;
5369
5360
}
5370
5361
}
5371
5362
} ;
0 commit comments