工农解放报第二期26.11
This commit is contained in:
1 parent
97e84fa6c4
commit
5977b1b272
17 files changed
+604
-46
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { DocuBuilder } from "./docu_builder.ts";
|
||||
import { md } from "../mdit/md.ts";
|
||||
|
||||
Deno.test("PDF rendering loads relative assets from configured file base", async () => {
|
||||
const chromiumPath = Deno.env.get("CHROMIUM_PATH");
|
||||
@@ -24,3 +25,65 @@ Deno.test("PDF rendering loads relative assets from configured file base", async
|
||||
assertEquals((await Deno.stat(pdfPath)).size > 0, true);
|
||||
await Deno.remove(pdfPath);
|
||||
});
|
||||
|
||||
Deno.test("PDF rendering waits for remote Markdown images", async () => {
|
||||
if (!Deno.env.get("CHROMIUM_PATH")) return;
|
||||
|
||||
const builder = new DocuBuilder({
|
||||
asset_base: "../../assets",
|
||||
journal: { build_js_script: false },
|
||||
});
|
||||
const pdfPath = await Deno.makeTempFile({ suffix: ".pdf" });
|
||||
await builder.with_browser();
|
||||
try {
|
||||
await builder.build_as_pdf({ path: pdfPath, format: "A4" }, [
|
||||
'<img src="https://imgbed.cmlmuf.org/i/2026/08/31/wd5mok.jpg" alt="Remote asset">',
|
||||
]);
|
||||
} finally {
|
||||
await builder.close_browser();
|
||||
}
|
||||
assertEquals((await Deno.stat(pdfPath)).size > 0, true);
|
||||
await Deno.remove(pdfPath);
|
||||
});
|
||||
|
||||
Deno.test("PDF rendering embeds publication-relative asset images", async () => {
|
||||
if (!Deno.env.get("CHROMIUM_PATH")) return;
|
||||
|
||||
const builder = new DocuBuilder({
|
||||
asset_base: "../../assets",
|
||||
journal: { build_js_script: false },
|
||||
});
|
||||
const resolvedHtml = (builder as any).resolveLocalAssetImages(
|
||||
'<img src="../../../assets/pictures/rsf.png">' +
|
||||
'<img src="https://example.test/remote.png">',
|
||||
);
|
||||
assertEquals(
|
||||
resolvedHtml.includes('src="data:image/png;base64,'),
|
||||
true,
|
||||
);
|
||||
assertEquals(
|
||||
resolvedHtml.includes('src="https://example.test/remote.png"'),
|
||||
true,
|
||||
);
|
||||
assertEquals(resolvedHtml.includes('loading="eager"'), false);
|
||||
const markdownHtml = md.render(
|
||||
"",
|
||||
);
|
||||
const eagerHtml = (builder as any).resolveLocalAssetImages(markdownHtml);
|
||||
assertEquals(eagerHtml.includes('loading="lazy"'), false);
|
||||
assertEquals(eagerHtml.includes('loading="eager"'), true);
|
||||
const pdfPath = await Deno.makeTempFile({ suffix: ".pdf" });
|
||||
await builder.with_browser();
|
||||
try {
|
||||
await builder.build_as_pdf({ path: pdfPath, format: "A4" }, [
|
||||
(builder as any).resolveLocalAssetImages(
|
||||
'<img src="../../../assets/pictures/26.11.0_pictures/ef1be4ca769fc52e513e69e1-129si8u.png" alt="Publication asset">',
|
||||
),
|
||||
]);
|
||||
} finally {
|
||||
await builder.close_browser();
|
||||
}
|
||||
const pdfText = new TextDecoder().decode(await Deno.readFile(pdfPath));
|
||||
assertEquals(pdfText.includes("/Subtype /Image"), true);
|
||||
await Deno.remove(pdfPath);
|
||||
});
|
||||
Reference in new issue
Block a user