From 2a2b543d8fa5d652f1ccfd482e86b6544c7abd2f Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 18:57:23 +0000 Subject: [PATCH 1/2] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/lib/docx-pleading.ts | 2 +- src/lib/pdf-pleading.ts | 62 ++++++++++++++++----------- src/routes/documents.pleading.new.tsx | 4 +- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/lib/docx-pleading.ts b/src/lib/docx-pleading.ts index 53f8459..a2fd1e9 100644 --- a/src/lib/docx-pleading.ts +++ b/src/lib/docx-pleading.ts @@ -85,7 +85,7 @@ const captionLeftBorders = { const captionRightBorders = { top: { style: BorderStyle.NONE, size: 0, color: "FFFFFF" }, - bottom: { style: BorderStyle.SINGLE, size: 8, color: "000000" }, + bottom: { style: BorderStyle.NONE, size: 0, color: "FFFFFF" }, left: { style: BorderStyle.NONE, size: 0, color: "FFFFFF" }, right: { style: BorderStyle.NONE, size: 0, color: "FFFFFF" }, }; diff --git a/src/lib/pdf-pleading.ts b/src/lib/pdf-pleading.ts index d6a55cc..d056a5c 100644 --- a/src/lib/pdf-pleading.ts +++ b/src/lib/pdf-pleading.ts @@ -62,38 +62,53 @@ function htmlToBlocks(html: string): Block[] { const walkList = (listEl: Element, ordered: boolean, level: number) => { let idx = 1; - listEl.querySelectorAll(":scope > li").forEach((li) => { - const tokens: Token[] = []; - li.childNodes.forEach((child) => { - if (child.nodeType === Node.ELEMENT_NODE && /^(ul|ol)$/i.test((child as Element).tagName)) return; - tokenize(child, {}, tokens); + Array.from(listEl.children) + .filter((child): child is Element => child.tagName.toLowerCase() === "li") + .forEach((li) => { + const tokens: Token[] = []; + li.childNodes.forEach((child) => { + if (child.nodeType === Node.ELEMENT_NODE && /^(ul|ol)$/i.test((child as Element).tagName)) return; + tokenize(child, {}, tokens); + }); + out.push({ kind: "list-item", ordered, level, index: idx++, tokens }); + Array.from(li.children) + .filter((child): child is Element => /^(ul|ol)$/i.test(child.tagName)) + .forEach((nested) => walkList(nested, nested.tagName.toLowerCase() === "ol", level + 1)); }); - out.push({ kind: "list-item", ordered, level, index: idx++, tokens }); - li.querySelectorAll(":scope > ul").forEach((n) => walkList(n as Element, false, level + 1)); - li.querySelectorAll(":scope > ol").forEach((n) => walkList(n as Element, true, level + 1)); - }); }; - Array.from(root.children).forEach((el) => { - const tag = el.tagName.toLowerCase(); - if (tag === "ul") return walkList(el, false, 0); - if (tag === "ol") return walkList(el, true, 0); + const walk = (node: Element) => { + const tag = node.tagName.toLowerCase(); + if (tag === "ul") return walkList(node, false, 0); + if (tag === "ol") return walkList(node, true, 0); if (tag === "blockquote") { const tokens: Token[] = []; - el.childNodes.forEach((c) => tokenize(c, {}, tokens)); - out.push({ kind: "para", align: alignOf(el), tokens, indent: 36 }); + node.childNodes.forEach((c) => tokenize(c, {}, tokens)); + out.push({ kind: "para", align: alignOf(node), tokens, indent: 36 }); return; } if (tag === "h1" || tag === "h2" || tag === "h3") { const tokens: Token[] = []; - el.childNodes.forEach((c) => tokenize(c, { bold: true }, tokens)); - out.push({ kind: "para", align: alignOf(el), tokens }); + node.childNodes.forEach((c) => tokenize(c, { bold: true }, tokens)); + out.push({ kind: "para", align: alignOf(node), tokens }); + return; + } + if (tag === "p") { + const tokens: Token[] = []; + node.childNodes.forEach((c) => tokenize(c, {}, tokens)); + out.push({ kind: "para", align: alignOf(node), tokens }); + return; + } + if (tag === "div" || tag === "section" || tag === "article") { + Array.from(node.children).forEach((child) => walk(child)); return; } const tokens: Token[] = []; - el.childNodes.forEach((c) => tokenize(c, {}, tokens)); - out.push({ kind: "para", align: alignOf(el), tokens }); - }); + node.childNodes.forEach((c) => tokenize(c, {}, tokens)); + if (tokens.length > 0) out.push({ kind: "para", align: alignOf(node), tokens }); + }; + + Array.from(root.children).forEach((el) => walk(el)); return out; } @@ -197,7 +212,6 @@ export async function downloadPleadingPdf(input: PleadingInput, filename: string const leftColW = CONTENT_W * 0.58; const leftX = MARGIN; const rightX = MARGIN + leftColW + 24; - const captionRightEdge = MARGIN + CONTENT_W; const labelIndent = 24; // ~1/3" indent for "Plaintiff(s)," / "Defendant(s)." const plaintiffLines = (input.plaintiffs || "").split("\n").filter((l) => l.trim()); @@ -230,10 +244,8 @@ export async function downloadPleadingPdf(input: PleadingInput, filename: string const captionEndY = ly; pdf.setLineWidth(0.6); - // Vertical divider between caption columns - pdf.line(MARGIN + leftColW + 12, captionStartY - LINE_H + 4, MARGIN + leftColW + 12, captionEndY); - // Bottom border spanning BOTH caption cells (full content width) - pdf.line(leftX, captionEndY + 2, captionRightEdge, captionEndY + 2); + // Bottom border only under the left caption cell + pdf.line(leftX, captionEndY + 2, MARGIN + leftColW + 12, captionEndY + 2); y = captionEndY + LINE_H; diff --git a/src/routes/documents.pleading.new.tsx b/src/routes/documents.pleading.new.tsx index 2749521..3bd20e5 100644 --- a/src/routes/documents.pleading.new.tsx +++ b/src/routes/documents.pleading.new.tsx @@ -304,8 +304,8 @@ function PleadingNewPage() {