fix: trim trailing whitespace from lheading text (#3920)

This commit is contained in:
Veer Shah
2026-03-20 09:06:07 -06:00
committed by GitHub
parent d4c0fe5871
commit 3ea7e88e15
2 changed files with 16 additions and 2 deletions
+3 -2
View File
@@ -574,12 +574,13 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
lheading(src: string): Tokens.Heading | undefined {
const cap = this.rules.block.lheading.exec(src);
if (cap) {
const text = cap[1].trim();
return {
type: 'heading',
raw: cap[0],
depth: cap[2].charAt(0) === '=' ? 1 : 2,
text: cap[1],
tokens: this.lexer.inline(cap[1]),
text,
tokens: this.lexer.inline(text),
};
}
}
+13
View File
@@ -165,6 +165,19 @@ lheading 2
});
});
it('lheading should trim trailing whitespace from text', () => {
expectTokens({
md: 'heading with trailing spaces \n==============================',
tokens: [{
type: 'heading',
raw: 'heading with trailing spaces \n==============================',
depth: 1,
text: 'heading with trailing spaces',
tokens: [{ type: 'text', raw: 'heading with trailing spaces', text: 'heading with trailing spaces', escaped: false }],
}],
});
});
it('should not be heading if depth > 6', () => {
expectTokens({
md: '####### heading 7',