Skip to content

Commit 0769124

Browse files
authored
feat: add def token in tokens and renderer (#3745)
* feat: add def token in tokens and renderer * fix tests
1 parent 5f4b638 commit 0769124

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/Lexer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
206206
href: token.href,
207207
title: token.title,
208208
};
209+
tokens.push(token);
209210
}
210211
continue;
211212
}

src/Parser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class _Parser<ParserOutput = string, RendererOutput = string> {
4949
if (this.options.extensions?.renderers?.[anyToken.type]) {
5050
const genericToken = anyToken as Tokens.Generic;
5151
const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
52-
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(genericToken.type)) {
52+
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'def', 'paragraph', 'text'].includes(genericToken.type)) {
5353
out += ret || '';
5454
continue;
5555
}
@@ -90,6 +90,10 @@ export class _Parser<ParserOutput = string, RendererOutput = string> {
9090
out += this.renderer.html(token);
9191
continue;
9292
}
93+
case 'def': {
94+
out += this.renderer.def(token);
95+
continue;
96+
}
9397
case 'paragraph': {
9498
out += this.renderer.paragraph(token);
9599
continue;

src/Renderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export class _Renderer<ParserOutput = string, RendererOutput = string> {
4949
return text as RendererOutput;
5050
}
5151

52+
def(token: Tokens.Def): RendererOutput {
53+
return '' as RendererOutput;
54+
}
55+
5256
heading({ tokens, depth }: Tokens.Heading): RendererOutput {
5357
return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>\n` as RendererOutput;
5458
}

test/unit/Lexer.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,15 @@ paragraph
13311331
links: {
13321332
link: { href: 'https://example.com', title: undefined },
13331333
},
1334+
tokens: [
1335+
{
1336+
type: 'def',
1337+
raw: '[link]: https://example.com',
1338+
tag: 'link',
1339+
href: 'https://example.com',
1340+
title: undefined,
1341+
},
1342+
],
13341343
});
13351344
});
13361345

@@ -1340,6 +1349,15 @@ paragraph
13401349
links: {
13411350
link: { href: 'https://example.com', title: 'title' },
13421351
},
1352+
tokens: [
1353+
{
1354+
type: 'def',
1355+
raw: '[link]: https://example.com "title"',
1356+
tag: 'link',
1357+
href: 'https://example.com',
1358+
title: 'title',
1359+
},
1360+
],
13431361
});
13441362
});
13451363
});

0 commit comments

Comments
 (0)