Skip to content

Commit 4732ad8

Browse files
TuYvTuYv
authored andcommitted
fix(export): preserve all deck slides for WeChat
1 parent ce362f1 commit 4732ad8

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

next/src/lib/export/__tests__/wechat.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, afterEach } from "vitest";
2-
import { toWechatHtmlFromDocument } from "../wechat";
2+
import { toWechatHtmlForExport, toWechatHtmlFromDocument } from "../wechat";
33

44
function parseFragment(html: string): HTMLBodyElement {
55
return new DOMParser().parseFromString(`<body>${html}</body>`, "text/html")
@@ -210,4 +210,19 @@ describe("toWechatHtmlFromDocument", () => {
210210
expect(style).not.toContain("180px");
211211
expect(style).not.toContain("96px");
212212
});
213+
214+
it("keeps every deck slide when the selected iframe contains only one slide", () => {
215+
const fullDeck = `<!doctype html><html><body>
216+
<section class="slide" data-slide-id="1"><h1>Slide one</h1></section>
217+
<section class="slide" data-slide-id="2"><h1>Slide two</h1></section>
218+
</body></html>`;
219+
const selectedSlide = new DOMParser().parseFromString(
220+
`<!doctype html><html><body><section class="slide"><h1>Slide two</h1></section></body></html>`,
221+
"text/html",
222+
);
223+
224+
const exported = toWechatHtmlForExport(fullDeck, selectedSlide);
225+
expect(exported).toContain("Slide one");
226+
expect(exported).toContain("Slide two");
227+
});
213228
});

next/src/lib/export/wechat.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import juice from "juice";
4+
import { isDeck } from "../deck";
45
import { copyHtml } from "./clipboard";
56

67
/**
@@ -105,9 +106,16 @@ export function toWechatHtmlFromDocument(renderedDoc: Document): string {
105106
return section.outerHTML;
106107
}
107108

109+
export function toWechatHtmlForExport(
110+
fullHtml: string,
111+
renderedDoc?: Document | null,
112+
): string {
113+
if (isDeck(fullHtml)) return toWechatHtml(fullHtml);
114+
return renderedDoc?.body ? toWechatHtmlFromDocument(renderedDoc) : toWechatHtml(fullHtml);
115+
}
116+
108117
export async function copyToWechat(fullHtml: string, renderedDoc?: Document | null): Promise<void> {
109-
const html = renderedDoc?.body ? toWechatHtmlFromDocument(renderedDoc) : toWechatHtml(fullHtml);
110-
await copyHtml(html);
118+
await copyHtml(toWechatHtmlForExport(fullHtml, renderedDoc));
111119
}
112120

113121
function inlineComputedTree(source: Element, clone: Element, view: Window): void {

0 commit comments

Comments
 (0)