Create flow cleanup leftover
This commit is contained in:
+36
-12
@@ -112,10 +112,12 @@ export function sectionsToCsv(
|
|||||||
const { img, file, bodyTrim } = labeledBlockMedia(b);
|
const { img, file, bodyTrim } = labeledBlockMedia(b);
|
||||||
const content = img
|
const content = img
|
||||||
? bodyTrim.length > 0
|
? bodyTrim.length > 0
|
||||||
? `${b.body}\n${img}`
|
? `${bodyTrim}\n${img}`
|
||||||
: img
|
: img
|
||||||
: file
|
: file
|
||||||
? `${b.body}\n${file}`
|
? bodyTrim.length > 0
|
||||||
|
? `${bodyTrim}\n${file}`
|
||||||
|
: file
|
||||||
: b.body;
|
: b.body;
|
||||||
rows.push([sec.categoryName, ent.title, b.label, content]);
|
rows.push([sec.categoryName, ent.title, b.label, content]);
|
||||||
}
|
}
|
||||||
@@ -235,6 +237,29 @@ export function sectionsToPdfBlob(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeBlockBodyParagraphs(body: string): void {
|
||||||
|
for (const p of splitDisplayParagraphs(body)) {
|
||||||
|
doc.setFont("helvetica", "normal");
|
||||||
|
doc.setFontSize(11);
|
||||||
|
const lines = doc.splitTextToSize(p, maxW);
|
||||||
|
const dim = doc.getTextDimensions(lines.join("\n"), { maxWidth: maxW });
|
||||||
|
ensureSpace(dim.h + 1);
|
||||||
|
doc.text(lines, margin, y);
|
||||||
|
y += dim.h + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Plain URL line(s); italic for images so captions vs URL read distinctly in print. */
|
||||||
|
function writeMediaUrlLines(url: string, fontStyle: "normal" | "italic"): void {
|
||||||
|
doc.setFont("helvetica", fontStyle);
|
||||||
|
doc.setFontSize(10);
|
||||||
|
const urlLines = doc.splitTextToSize(url, maxW);
|
||||||
|
const urlDim = doc.getTextDimensions(urlLines.join("\n"), { maxWidth: maxW });
|
||||||
|
ensureSpace(urlDim.h + 1);
|
||||||
|
doc.text(urlLines, margin, y);
|
||||||
|
y += urlDim.h + 2;
|
||||||
|
}
|
||||||
|
|
||||||
doc.setFont("helvetica", "bold");
|
doc.setFont("helvetica", "bold");
|
||||||
doc.setFontSize(16);
|
doc.setFontSize(16);
|
||||||
{
|
{
|
||||||
@@ -294,16 +319,15 @@ export function sectionsToPdfBlob(
|
|||||||
doc.text(lines, margin, y);
|
doc.text(lines, margin, y);
|
||||||
y += dim.h + 2;
|
y += dim.h + 2;
|
||||||
}
|
}
|
||||||
for (const p of splitDisplayParagraphs(b.body)) {
|
const { img, file } = labeledBlockMedia(b);
|
||||||
doc.setFont("helvetica", "normal");
|
if (img) {
|
||||||
doc.setFontSize(11);
|
writeBlockBodyParagraphs(b.body);
|
||||||
const lines = doc.splitTextToSize(p, maxW);
|
writeMediaUrlLines(img, "italic");
|
||||||
const dim = doc.getTextDimensions(lines.join("\n"), {
|
} else if (file) {
|
||||||
maxWidth: maxW,
|
writeBlockBodyParagraphs(b.body);
|
||||||
});
|
writeMediaUrlLines(file, "normal");
|
||||||
ensureSpace(dim.h + 1);
|
} else {
|
||||||
doc.text(lines, margin, y);
|
writeBlockBodyParagraphs(b.body);
|
||||||
y += dim.h + 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
exportFilenameBase,
|
exportFilenameBase,
|
||||||
sectionsToCsv,
|
sectionsToCsv,
|
||||||
sectionsToMarkdown,
|
sectionsToMarkdown,
|
||||||
|
sectionsToPdfBlob,
|
||||||
} from "../../../lib/create/ruleExport";
|
} from "../../../lib/create/ruleExport";
|
||||||
import type { CommunityRuleSection } from "../../../app/components/type/CommunityRule/CommunityRule.types";
|
import type { CommunityRuleSection } from "../../../app/components/type/CommunityRule/CommunityRule.types";
|
||||||
|
|
||||||
@@ -134,6 +135,37 @@ describe("ruleExport", () => {
|
|||||||
expect(html).toContain("Download");
|
expect(html).toContain("Download");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("sectionsToPdfBlob embeds image and file URLs as text for labeled blocks", async () => {
|
||||||
|
const sections: CommunityRuleSection[] = [
|
||||||
|
{
|
||||||
|
categoryName: "Values",
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
title: "Entry",
|
||||||
|
body: "",
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
label: "Photo",
|
||||||
|
body: "Caption",
|
||||||
|
imageUrl: "https://cdn.example.com/pic.jpg",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Handbook",
|
||||||
|
body: "Download",
|
||||||
|
fileUrl: "https://cdn.example.com/guidance.pdf",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const blob = sectionsToPdfBlob("Rule", null, sections);
|
||||||
|
const buf = new Uint8Array(await readBlobAsArrayBuffer(blob));
|
||||||
|
const raw = new TextDecoder("latin1").decode(buf);
|
||||||
|
expect(raw).toContain("https://cdn.example.com/pic.jpg");
|
||||||
|
expect(raw).toContain("https://cdn.example.com/guidance.pdf");
|
||||||
|
});
|
||||||
|
|
||||||
it("buildPrintableRuleHtmlDocument escapes HTML in user content", () => {
|
it("buildPrintableRuleHtmlDocument escapes HTML in user content", () => {
|
||||||
const sections: CommunityRuleSection[] = [
|
const sections: CommunityRuleSection[] = [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user