mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
feat: add def token in tokens and renderer (#3745)
* feat: add def token in tokens and renderer * fix tests
This commit is contained in:
@@ -206,6 +206,7 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
|
||||
href: token.href,
|
||||
title: token.title,
|
||||
};
|
||||
tokens.push(token);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
+5
-1
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user