From 88edde9b5127669b3d59e6b1969ebe352ae7e6d6 Mon Sep 17 00:00:00 2001 From: thangho <33411543+thangho98@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:42:21 +0700 Subject: [PATCH] fix(gen-full): Avoid infinite loop when converting table/TOC to Markdown The existing turndown rule for 'table' elements caused a "Maximum call stack size exceeded" error due to recursive processing, particularly on pages with a Table of Contents (TOC). This fix isolates the table conversion logic by using a dedicated turndown instance, preventing the infinite recursion caused by rule conflicts. --- src/cli/actions/gen.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cli/actions/gen.js b/src/cli/actions/gen.js index 5064966..e9e9123 100644 --- a/src/cli/actions/gen.js +++ b/src/cli/actions/gen.js @@ -268,10 +268,19 @@ async function genFull(sitemapUrl) { emDelimiter: '*', hr: '---', }); + // Configure Turndown for table content + const turndownServiceForTable = new TurndownService({ + codeBlockStyle: 'fenced', + headingStyle: 'atx', + bulletListMarker: '-', + emDelimiter: '*', + hr: '---', + }); + // add rule for table content turndownService.addRule('table', { filter: 'table', replacement: function(content, node) { - return '\n' + turndownService.turndown(node.outerHTML) + '\n'; + return '\n' + turndownServiceForTable.turndown(node.outerHTML) + '\n'; } }); let output = '';