From d4e492351b55a29e875e234154fd2400acc973a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=BF=9B?= Date: Mon, 27 Jul 2026 17:25:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A0=20slide=20=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E6=97=B6=20fallback=20=E5=88=B0=20body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 测试页没有 page/slide-* 命名的容器,findSlides 返回 0。 新增 fallback:自动用 body 元素作为 slide 容器。 --- convert-w2p.js | 13 ++++++++++++- web-to-ppt/convert-browser.js | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/convert-w2p.js b/convert-w2p.js index aeafe46..02dac87 100644 --- a/convert-w2p.js +++ b/convert-w2p.js @@ -421,7 +421,18 @@ async function convert(input) { } const canvasArea = (canvas.width || 0) * (canvas.height || 0); - const slideContainers = findSlides(inputRoot, canvasArea); + var slideContainers = findSlides(inputRoot, canvasArea); + // fallback:没有匹配的 slide 容器时,用 body 作为 slide + if (slideContainers.length === 0) { + function findBody(node) { + if (!node) return null; + if (node.tag === 'BODY' && node.rect) return node; + if (node.children) for (const c of node.children) { const r = findBody(c); if (r) return r; } + return null; + } + const bodyNode = findBody(inputRoot); + if (bodyNode) slideContainers = [bodyNode]; + } console.log(`找到 ${slideContainers.length} 个 slide 容器`); const slideGroups = slideContainers.map(s => ({ diff --git a/web-to-ppt/convert-browser.js b/web-to-ppt/convert-browser.js index ec42832..b8697e4 100644 --- a/web-to-ppt/convert-browser.js +++ b/web-to-ppt/convert-browser.js @@ -140,7 +140,18 @@ async function convertToPptx(input, onProgress) { // 2. 识别 slide const canvasArea = (canvas.width || 0) * (canvas.height || 0); - const slideContainers = findSlides(inputRoot, canvasArea); + var slideContainers = findSlides(inputRoot, canvasArea); + // fallback:没有匹配的 slide 容器时,用 body 作为 slide + if (slideContainers.length === 0) { + function findBody(node) { + if (!node) return null; + if (node.tag === 'BODY' && node.rect) return node; + if (node.children) for (const c of node.children) { const r = findBody(c); if (r) return r; } + return null; + } + const bodyNode = findBody(inputRoot); + if (bodyNode) slideContainers = [bodyNode]; + } // 3. 收集子节点 const slideGroups = slideContainers.map(s => ({