Improve the export pipeline (shared ordering + chapter page breaks)

- buildDocx/buildOdt now accept an explicit ordered chapter list, making that
  list the single source of truth for export ordering (defaults to whole book)
- Emit real page breaks between chapters in DOCX, with none before the first
- Unify the DOCX/ODT handlers into one exportOffice pipeline (ODT still built
  from the same DOCX via LibreOffice)
This commit is contained in:
avi 2026-08-20 11:44:54 -05:00
commit 7037cd9fc0
3 changed files with 55 additions and 53 deletions

View file

@ -206,7 +206,16 @@ check("docx body size is 12pt (24 half-points)", /<w:sz w:val="24"\/>/.test(docx
// paragraphs. Attributes may be emitted in any order, so match loosely.
check("docx has 1.7 line spacing", /<w:spacing[^>]*w:line="408"[^>]*w:lineRule="auto"[^>]*\/>/.test(docxXml));
check("docx has blank-line paragraph spacing", /<w:spacing[^>]*w:after="408"/.test(docxXml));
check("docx has chapter break before later chapters", (docxXml.match(/w:before="320"/g) || []).length >= 4);
// Each chapter after the first begins on a new page (a real w:pageBreakBefore),
// and there must be no page break before the first chapter (no blank first page).
const pageBreaks = docxXml.match(/<w:pageBreakBefore\/>/g) || [];
check("docx has a page break before later chapters", pageBreaks.length >= 4);
const firstBreak = docxXml.indexOf("<w:pageBreakBefore/>");
const titleIdx = docxXml.indexOf("Office Test Book");
check(
"docx page breaks come after the book title (no blank first page)",
firstBreak === -1 || firstBreak > titleIdx
);
check("docx has callout shading", /w:fill="F5F2ED"/.test(docxXml));
check("docx renders highlight (no raw markup)", !docxText.includes("==highlight=="));
check("docx renders bold (no raw markup)", !docxText.includes("**bold**"));