fix: 无 slide 容器时 fallback 到 body

测试页没有 page/slide-* 命名的容器,findSlides 返回 0。
新增 fallback:自动用 body 元素作为 slide 容器。
This commit is contained in:
李进
2026-07-27 17:25:37 +08:00
parent ce89ee1b4d
commit d4e492351b
2 changed files with 24 additions and 2 deletions
+12 -1
View File
@@ -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 => ({