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 => ({