fix: 无 slide 容器时 fallback 到 body
测试页没有 page/slide-* 命名的容器,findSlides 返回 0。 新增 fallback:自动用 body 元素作为 slide 容器。
This commit is contained in:
@@ -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 => ({
|
||||
|
||||
Reference in New Issue
Block a user