From 505b9e5dbbfa9946cca54c788839394618862c99 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 3 Jun 2026 07:51:01 -0400 Subject: [PATCH] test: Cover math block table-cell serialization Add a test mirroring the code fence case to guard the MathBlock half of the table-cell
encoding and pipe/backslash escaping. Co-Authored-By: Claude Opus 4.8 --- server/models/helpers/DocumentHelper.test.ts | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/server/models/helpers/DocumentHelper.test.ts b/server/models/helpers/DocumentHelper.test.ts index 6bca0e689a..d829c1ce91 100644 --- a/server/models/helpers/DocumentHelper.test.ts +++ b/server/models/helpers/DocumentHelper.test.ts @@ -694,6 +694,62 @@ This is a [test paragraph](https://example.net)`, expect(result).not.toMatch(/```abap\n/); }); + it("should export math blocks inside table cells on a single line", async () => { + const document = await buildDocument({ + content: { + type: "doc", + content: [ + { + type: "table", + content: [ + { + type: "tr", + content: [ + { + type: "th", + attrs: { colspan: 1, rowspan: 1 }, + content: [ + { + type: "paragraph", + content: [{ type: "text", text: "Header" }], + }, + ], + }, + ], + }, + { + type: "tr", + content: [ + { + type: "td", + attrs: { colspan: 1, rowspan: 1 }, + content: [ + { + type: "math_block", + content: [ + { type: "text", text: "a | b\n\\frac{1}{2}" }, + ], + }, + ], + }, + ], + }, + ], + }, + ], + }, + }); + const result = await DocumentHelper.toMarkdown(document, { + includeTitle: false, + }); + // Math blocks inside tables should use
tags rather than literal + // newlines that would break the table row structure, with pipes and + // backslashes escaped so the content cannot break out of the column. + expect(result).toContain("$$
a \\| b
\\\\frac{1}{2}
$$"); + // The block content must not introduce raw newlines inside the table. + expect(result).not.toMatch(/\$\$\n/); + }); + it("should include collection title by default", async () => { const collection = await buildCollection({ name: "Test Collection",