mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: preserve zero from named extension renderers (#4199)
This commit is contained in:
+2
-2
@@ -52,7 +52,7 @@ export class _Parser<ParserOutput = string, RendererOutput = string> {
|
|||||||
const genericToken = anyToken as Tokens.Generic;
|
const genericToken = anyToken as Tokens.Generic;
|
||||||
const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
|
const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
|
||||||
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'checkbox', 'html', 'def', 'paragraph', 'text'].includes(genericToken.type)) {
|
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'checkbox', 'html', 'def', 'paragraph', 'text'].includes(genericToken.type)) {
|
||||||
out += ret || '';
|
out += ret === false ? '' : ret ?? '';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ export class _Parser<ParserOutput = string, RendererOutput = string> {
|
|||||||
if (this.options.extensions?.renderers?.[anyToken.type]) {
|
if (this.options.extensions?.renderers?.[anyToken.type]) {
|
||||||
const ret = this.options.extensions.renderers[anyToken.type].call({ parser: this }, anyToken);
|
const ret = this.options.extensions.renderers[anyToken.type].call({ parser: this }, anyToken);
|
||||||
if (ret !== false || !['escape', 'html', 'link', 'image', 'checkbox', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(anyToken.type)) {
|
if (ret !== false || !['escape', 'html', 'link', 'image', 'checkbox', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(anyToken.type)) {
|
||||||
out += ret || '';
|
out += ret === false ? '' : ret ?? '';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -344,6 +344,25 @@ describe('marked unit', () => {
|
|||||||
assert.strictEqual(html, 'fallbacktest');
|
assert.strictEqual(html, 'fallbacktest');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should keep zero from both block and inline extension renderers', () => {
|
||||||
|
const extension = level => ({
|
||||||
|
name: level + 'Count',
|
||||||
|
level,
|
||||||
|
tokenizer(src) {
|
||||||
|
if (src.startsWith(':count:')) {
|
||||||
|
return { type: level + 'Count', raw: ':count:' };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
renderer() {
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
marked.use({ extensions: [extension('block'), extension('inline')] });
|
||||||
|
|
||||||
|
assert.strictEqual(marked.parse(':count:'), '0');
|
||||||
|
assert.strictEqual(marked.parseInline(':count:'), '0');
|
||||||
|
});
|
||||||
|
|
||||||
it('should fall back when tokenizers return false', () => {
|
it('should fall back when tokenizers return false', () => {
|
||||||
const extension = {
|
const extension = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
|
|||||||
Reference in New Issue
Block a user