From afbb27c7ee753af07fb1a5c18031fc3068261b31 Mon Sep 17 00:00:00 2001 From: Bao Nguyen <39545125+giaBaoJS@users.noreply.github.com> Date: Tue, 8 Sep 2026 22:31:59 +0700 Subject: [PATCH] fix: allow tabs in the thematic break that ends a list item (#4087) CommonMark 0.31.2 says each -, _, or * of a thematic break may be followed by any number of spaces or tabs, but the hrRegex that closes a list item allowed spaces only, so a break written with tabs was taken as paragraph continuation instead. "- foo" followed by a line of underscores separated by tabs put the hr inside the list item, and "- foo" followed by "---" plus a tab turned foo into a setext heading. The block hr rule already allows tabs; this makes the list item check agree with it. --- src/rules.ts | 2 +- .../new/thematic_break_with_tabs_ends_list.html | 12 ++++++++++++ test/specs/new/thematic_break_with_tabs_ends_list.md | 11 +++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/thematic_break_with_tabs_ends_list.html create mode 100644 test/specs/new/thematic_break_with_tabs_ends_list.md diff --git a/src/rules.ts b/src/rules.ts index 601b5a3b..7d847035 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -93,7 +93,7 @@ export const other = { endingNewline: /\n$/, listItemRegex: (bull: string) => new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`)), - hrRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)), + hrRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}((?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\\*[ \t]*){3,})(?:\\n+|$)`)), fencesBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:\`\`\`|~~~)`)), headingBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}#`)), htmlBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}<(?:[a-z].*>|!--)`, 'i')), diff --git a/test/specs/new/thematic_break_with_tabs_ends_list.html b/test/specs/new/thematic_break_with_tabs_ends_list.html new file mode 100644 index 00000000..f9e832f2 --- /dev/null +++ b/test/specs/new/thematic_break_with_tabs_ends_list.html @@ -0,0 +1,12 @@ + +
+ +
+ +
diff --git a/test/specs/new/thematic_break_with_tabs_ends_list.md b/test/specs/new/thematic_break_with_tabs_ends_list.md new file mode 100644 index 00000000..871daa6e --- /dev/null +++ b/test/specs/new/thematic_break_with_tabs_ends_list.md @@ -0,0 +1,11 @@ +--- +gfm: false +--- +- foo +_ _ _ + +- bar +*** + +- baz +---