fix: fix recursion-like stack overflow error caused by the old render… (#3380)

Co-authored-by: tylerccwang <tylerccwang@tencent.com>
This commit is contained in:
yijian166 2024-07-29 01:28:06 +08:00 committed by GitHub
parent 829453b48e
commit 89af0b85b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -153,13 +153,13 @@ export class Marked {
}
const rendererProp = prop as Exclude<keyof _Renderer, 'options' | 'parser'>;
let rendererFunc = pack.renderer[rendererProp] as GenericRendererFunction;
if (!pack.useNewRenderer) {
// TODO: Remove this in next major version
rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer) as GenericRendererFunction;
}
const prevRenderer = renderer[rendererProp] as GenericRendererFunction;
// Replace renderer with func to run extension, but fall back if false
renderer[rendererProp] = (...args: unknown[]) => {
if (!pack.useNewRenderer) {
// TODO: Remove this in next major version
rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer) as GenericRendererFunction;
}
let ret = rendererFunc.apply(renderer, args);
if (ret === false) {
ret = prevRenderer.apply(renderer, args);