mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: allow a tab before the closing sequence of an ATX heading (#4084)
CommonMark 0.31.2 says the optional closing sequence of #s must be preceded by spaces or tabs, but the heading tokenizer tested for a space only, so `# foo<tab>#` kept the trailing hashes as content. The shared endingSpaceChar rule stays space only because code spans need exactly that, so the heading path gets its own rule.
This commit is contained in:
+2
-2
@@ -138,8 +138,8 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
|
||||
const trimmed = rtrim(text, '#');
|
||||
if (this.options.pedantic) {
|
||||
text = trimmed.trim();
|
||||
} else if (!trimmed || this.rules.other.endingSpaceChar.test(trimmed)) {
|
||||
// CommonMark requires space before trailing #s
|
||||
} else if (!trimmed || this.rules.other.endingSpaceTabChar.test(trimmed)) {
|
||||
// CommonMark requires a space or tab before trailing #s
|
||||
text = trimmed.trim();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ export const other = {
|
||||
endingHash: /#$/,
|
||||
startingSpaceChar: /^ /,
|
||||
endingSpaceChar: / $/,
|
||||
endingSpaceTabChar: /[ \t]$/,
|
||||
nonSpaceChar: /[^ ]/,
|
||||
newLineCharGlobal: /\n/g,
|
||||
tabCharGlobal: /\t/g,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<h1>foo</h1>
|
||||
<h2>bar</h2>
|
||||
<h3>baz #</h3>
|
||||
<h4>qux</h4>
|
||||
<h5>quux#</h5>
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
gfm: false
|
||||
---
|
||||
# foo #
|
||||
## bar ###
|
||||
### baz # #
|
||||
#### qux #
|
||||
##### quux#
|
||||
Reference in New Issue
Block a user