mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: trim trailing whitespace from lheading text (#3920)
This commit is contained in:
+3
-2
@@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user