feat: add def token in tokens and renderer (#3745)

* feat: add def token in tokens and renderer

* fix tests
This commit is contained in:
Tony Brix
2025-08-17 18:52:26 -06:00
committed by GitHub
parent 5f4b638e09
commit 07691248df
4 changed files with 28 additions and 1 deletions
+1
View File
@@ -206,6 +206,7 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
href: token.href,
title: token.title,
};
tokens.push(token);
}
continue;
}
+5 -1
View File
@@ -49,7 +49,7 @@ export class _Parser<ParserOutput = string, RendererOutput = string> {
if (this.options.extensions?.renderers?.[anyToken.type]) {
const genericToken = anyToken as Tokens.Generic;
const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(genericToken.type)) {
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'def', 'paragraph', 'text'].includes(genericToken.type)) {
out += ret || '';
continue;
}
@@ -90,6 +90,10 @@ export class _Parser<ParserOutput = string, RendererOutput = string> {
out += this.renderer.html(token);
continue;
}
case 'def': {
out += this.renderer.def(token);
continue;
}
case 'paragraph': {
out += this.renderer.paragraph(token);
continue;
+4
View File
@@ -49,6 +49,10 @@ export class _Renderer<ParserOutput = string, RendererOutput = string> {
return text as RendererOutput;
}
def(token: Tokens.Def): RendererOutput {
return '' as RendererOutput;
}
heading({ tokens, depth }: Tokens.Heading): RendererOutput {
return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>\n` as RendererOutput;
}
+18
View File
@@ -1331,6 +1331,15 @@ paragraph
links: {
link: { href: 'https://example.com', title: undefined },
},
tokens: [
{
type: 'def',
raw: '[link]: https://example.com',
tag: 'link',
href: 'https://example.com',
title: undefined,
},
],
});
});
@@ -1340,6 +1349,15 @@ paragraph
links: {
link: { href: 'https://example.com', title: 'title' },
},
tokens: [
{
type: 'def',
raw: '[link]: https://example.com "title"',
tag: 'link',
href: 'https://example.com',
title: 'title',
},
],
});
});
});