Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3d50c33
Add font family and size to the Markdown and LaTeX Visual editors
Tova22 Nov 9, 2026
4602a38
Keep local font size and family in the Word export
Tova22 Nov 9, 2026
9b390f1
Reject unknown font names in pasted HTML and keep LaTeX size groups o…
Tova22 Nov 10, 2026
d281e8b
Keep font size proportions in the Word export, keep blank lines in fr…
Tova22 Nov 10, 2026
2f907d3
Do not carry a font around a footnote reference into the footnote, an…
Tova22 Nov 10, 2026
acd7bf1
feat(documents): numeric font sizes in points and a named-font catalogue
Tova22 Nov 11, 2026
30d2684
feat(latex): named fonts in the Visual editor, fix-cm for exact sizes…
Tova22 Nov 11, 2026
83c7e7b
fix(documents): nested same-kind font spans, front matter position, l…
Tova22 Nov 11, 2026
b11c62b
fix(documents): readable contrast and spacing in the font panel
Tova22 Nov 11, 2026
82711c3
fix(word): keep the braces of LaTeX size groups so every group form e…
Tova22 Nov 11, 2026
3cbb2f5
test(markdown): font size applies to every selected table cell
Tova22 Nov 11, 2026
e51bfdb
fix(documents): review fixes - tolerant fontsize read in Word export,…
Tova22 Nov 11, 2026
d6adc68
feat(documents): font list opens on click; compact size stepper witho…
Tova22 Nov 11, 2026
c443840
fix(documents): size field shows the current size and steps from it
Tova22 Nov 11, 2026
70aeec6
feat(documents): size applies to the word at a caret; size button in …
Tova22 Nov 11, 2026
9fa59e1
Close font and size panels on Enter and show the result
Tova22 Nov 12, 2026
54a77e7
Show an empty size and font field for a selection that mixes several
Tova22 Nov 12, 2026
9d5ca16
docs: font and size behaviour at a caret, on Enter and for mixed sele…
Tova22 Nov 12, 2026
d6e7605
fix(latex): Default in the document font card removes only the active…
Tova22 Nov 12, 2026
bc02c87
feat(latex): the document font card lists the named-font catalogue
Tova22 Nov 12, 2026
9f8639d
fix(documents): keep the selection toolbar still while its size panel…
Tova22 Nov 12, 2026
0dea792
fix(documents): whitespace is not styled content; fonts skip inline code
Tova22 Nov 15, 2026
25c07c4
fix(documents): whitespace rule leaves links and code alone; add real…
Tova22 Nov 16, 2026
97e83cf
docs(documents): describe the whitespace rule for sizes, fonts and em…
Tova22 Nov 16, 2026
e044c41
fix(documents): code drops sizes, accents stay in the sized word, str…
Tova22 Nov 16, 2026
484c60e
test(documents): replay the reported gestures with real keys; cover d…
Tova22 Nov 16, 2026
b5eef10
fix(documents): an apostrophe between two letters belongs to the word…
Tova22 Nov 16, 2026
8ff7370
fix(latex): load fonts from a light package entry so the Visual worke…
Tova22 Nov 20, 2026
be71c8f
fix(word): read the LaTeX document font and LaTeX's 10 pt default in …
Tova22 Nov 20, 2026
aaa12ac
fix(documents): one rule for the caret word and the shown font in bot…
Tova22 Nov 20, 2026
a2c53a9
feat(documents): + and − move each word of a mixed selection and keep…
Tova22 Nov 20, 2026
f11278b
fix(markdown): write size and font tags outside every other style
Tova22 Nov 20, 2026
3e9b407
feat(documents): size presets in the size field and Mod+> / Mod+< sho…
Tova22 Nov 20, 2026
172a454
test(word): export the LaTeX card's named font at 10 pt with the real…
Tova22 Nov 20, 2026
c71e98a
docs(documents): size presets, Mod+> / Mod+<, per-word steps, tag order
Tova22 Nov 20, 2026
fd0cf8a
fix(markdown): keep size and font tags outside emphasis inside a word…
Tova22 Nov 20, 2026
917f644
fix(documents): minus, plus and arrows always step each run from its …
Tova22 Nov 20, 2026
718456a
fix(word): the LaTeX base font follows the declaration that sets the …
Tova22 Nov 20, 2026
832bff8
fix(documents): the size list marks the size shown in the field
Tova22 Nov 20, 2026
8dd28df
fix(documents): the size panel stays open while plus and minus are cl…
Tova22 Nov 22, 2026
7027336
fix(documents): a run of line breaks at a style change leaves the tag…
Tova22 Nov 22, 2026
56b4d68
fix(documents): size shortcuts are Mod+Shift+. and Mod+Shift+, by key…
Tova22 Nov 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 224 additions & 0 deletions apps/server/src/scient/pandoc/PandocWordConverter.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,228 @@ describe.skipIf(binary === null)("Word export with the real Pandoc (local integr
}),
),
);
describe("local font size and family", () => {
const exportMarkdown = (name: string, markdown: string) =>
withConverter(({ converter, directory }) =>
Effect.gen(function* () {
const { docx, result } = yield* convertTo(converter, directory, name, {
bundle: makeBundle({ markdown }),
});
return {
document: docx.text("word/document.xml"),
styles: docx.text("word/styles.xml"),
warnings: result.warnings.map((warning) => warning.message).join("\n"),
};
}),
);

it.live("applies a size in points as a Word character style", () =>
Effect.gen(function* () {
const { document, styles, warnings } = yield* exportMarkdown(
"font-size-span",
'Some <span style="font-size:13.5pt">big</span> words.',
);
expect(document).toMatch(
/<w:rStyle w:val="Scient13_5pt"\s*\/>[\s\S]*?<w:t[^>]*>big<\/w:t>/u,
);
expect(styles).toMatch(/w:styleId="Scient13_5pt"[\s\S]*?<w:sz w:val="27"\s*\/>/u);
expect(warnings).not.toContain("Raw HTML");
expect(document).not.toContain("&lt;span");
}),
);

it.live("applies a named font as a Word character style", () =>
Effect.gen(function* () {
const { document, styles } = yield* exportMarkdown(
"font-family-span",
"Some <span style=\"font-family:'Courier New'\">code</span> words.",
);
expect(document).toMatch(/<w:rStyle w:val="ScientCourierNew"\s*\/>[\s\S]*?code/u);
expect(styles).toMatch(/w:styleId="ScientCourierNew"[\s\S]*?w:ascii="Courier New"/u);
}),
);

it.live("keeps both when a size span and a font span are nested", () =>
Effect.gen(function* () {
const { document } = yield* exportMarkdown(
"font-nested",
'Some <span style="font-size:14pt">big <span style="font-family:\'Arial\'">words</span></span> here.',
);
const sizeRun = /<w:r>(?:(?!<\/w:r>)[\s\S])*?big/u.exec(document)?.[0] ?? "";
const wordsRun = /<w:r>(?:(?!<\/w:r>)[\s\S])*?words/u.exec(document)?.[0] ?? "";
expect(sizeRun).toContain("Scient14pt");
expect(wordsRun).toContain("ScientArial14pt");
}),
);

it.live("keeps an absolute size inside a heading and a footnote", () =>
Effect.gen(function* () {
const { document, styles } = yield* exportMarkdown(
"font-heading",
'# Title with <span style="font-size:20pt">big</span> word\n\nText[^1]\n\n[^1]: Note <span style="font-size:20pt">big</span>.\n',
);
expect(document).toMatch(/<w:rStyle w:val="Scient20pt"\s*\/>[\s\S]*?<w:t[^>]*>big<\/w:t>/u);
expect(styles).toMatch(/w:styleId="Scient20pt"[\s\S]*?<w:sz w:val="40"\s*\/>/u);
}),
);

it.live("keeps the link look on a sized run inside a link", () =>
Effect.gen(function* () {
const { document, styles } = yield* exportMarkdown(
"font-link",
'See [a <span style="font-size:14pt">big</span> link](https://example.com).',
);
expect(document).toMatch(/<w:rStyle w:val="Scient14ptlink"\s*\/>[\s\S]*?big/u);
expect(styles).toMatch(
/w:styleId="Scient14ptlink"[\s\S]*?<w:sz w:val="28"\s*\/>[\s\S]*?<w:u w:val="single"/u,
);
}),
);

it.live("still drops every other span", () =>
Effect.gen(function* () {
const { document, warnings } = yield* exportMarkdown(
"font-other-span",
'Some <span style="color:red">plain</span> words.',
);
expect(document).toContain("plain");
expect(document).not.toContain("ScientSize");
expect(document).not.toContain("color");
expect(warnings).toContain("Raw HTML was left out");
}),
);

it.live("sets the base font and size from the front matter", () =>
Effect.gen(function* () {
const { styles } = yield* exportMarkdown(
"font-front-matter",
"---\nfontsize: 12pt\nmainfont: Times New Roman\n---\n\nText.\n",
);
expect(styles).toMatch(
/<w:docDefaults>[\s\S]*?w:ascii="Times New Roman"[\s\S]*?<w:sz w:val="24"\s*\/>/u,
);
}),
);
const exportLatex = (name: string, tex: string) =>
withConverter(({ converter, directory }) =>
Effect.gen(function* () {
const paper = NodePath.join(directory, "paper");
NodeFS.mkdirSync(paper, { recursive: true });
NodeFS.writeFileSync(NodePath.join(paper, "main.tex"), tex);
const latex = yield* prepareLatexProject(NodePath.join(paper, "main.tex"), directory);
const { docx } = yield* convertTo(converter, directory, name, {
bundle: makeBundle({ markdown: "" }),
latex,
files: { baseDirectory: paper, allowRoots: [paper] },
});
return { document: docx.text("word/document.xml"), styles: docx.text("word/styles.xml") };
}),
);

it.live("keeps LaTeX size groups and family commands as Word character styles", () =>
Effect.gen(function* () {
const { document } = yield* exportLatex(
"latex-font",
[
"\\documentclass{article}",
"\\begin{document}",
"A {\\fontsize{14.4}{17.3}\\selectfont big \\textsf{both}} and \\textrm{roman} and {\\small tiny}.",
"\\end{document}",
].join("\n"),
);
const run = (text: string) =>
new RegExp(`<w:r>(?:(?!</w:r>)[\\s\\S])*?${text}`, "u").exec(document)?.[0] ?? "";
expect(run("big")).toContain("Scient14_4pt");
expect(run("both")).toContain("ScientArial14_4pt");
expect(run("roman")).toContain("ScientTimesNewRoman");
expect(run("tiny")).toContain("Scient9pt");
expect(document).not.toContain("scient-size");
}),
);

it.live("exports size groups next to commands and inside arguments", () =>
Effect.gen(function* () {
const { document } = yield* exportLatex(
"latex-brace-forms",
[
"\\documentclass{article}",
"\\begin{document}",
"\\section {\\large Intro}",
"Body\\footnote {\\small note}. a{\\Large b}c and \\textbf{x}{\\large y}.",
"\\end{document}",
].join("\n"),
);
const run = (text: string) =>
new RegExp(`<w:r>(?:(?!</w:r>)[\\s\\S])*?${text}`, "u").exec(document)?.[0] ?? "";
expect(run("Intro")).toContain("Scient12pt");
expect(run(">b<")).toContain("Scient14_4pt");
expect(run(">y<")).toContain("Scient12pt");
expect(document).not.toContain("scient-size");
}),
);

it.live("keeps a LaTeX font family group as a Word character style", () =>
Effect.gen(function* () {
const { document } = yield* exportLatex(
"latex-font-family",
[
"\\documentclass{article}",
"\\begin{document}",
"A {\\fontfamily{qtm}\\selectfont serif} text.",
"\\end{document}",
].join("\n"),
);
const run = /<w:r>(?:(?!<\/w:r>)[\s\S])*?serif/u.exec(document)?.[0] ?? "";
expect(run).toContain("ScientTimesNewRoman");
}),
);

it.live("takes the base font from the LaTeX class option and \\familydefault", () =>
Effect.gen(function* () {
const { styles } = yield* exportLatex(
"latex-base-font",
[
"\\documentclass[12pt]{article}",
"\\renewcommand{\\familydefault}{\\rmdefault}",
"\\begin{document}",
"Text.",
"\\end{document}",
].join("\n"),
);
expect(styles).toMatch(
/<w:docDefaults>[\s\S]*?Times New Roman[\s\S]*?<w:sz w:val="24"\s*\/>/u,
);
}),
);

it.live("takes the named font the document settings card writes, at LaTeX's 10 pt", () =>
Effect.gen(function* () {
const pdftex = yield* exportLatex(
"latex-card-font-pdftex",
[
"\\documentclass{article}",
"\\renewcommand{\\familydefault}{qtm}",
"\\begin{document}",
"Text.",
"\\end{document}",
].join("\n"),
);
expect(pdftex.styles).toMatch(
/<w:docDefaults>[\s\S]*?Times New Roman[\s\S]*?<w:sz w:val="20"\s*\/>/u,
);
const fontspec = yield* exportLatex(
"latex-card-font-fontspec",
[
"\\documentclass{article}",
"\\usepackage{fontspec}",
"\\setmainfont{Calibri}",
"\\begin{document}",
"Text.",
"\\end{document}",
].join("\n"),
);
expect(fontspec.styles).toMatch(/<w:docDefaults>[\s\S]*?Calibri/u);
}),
);
});
});
18 changes: 15 additions & 3 deletions apps/server/src/scient/pandoc/PandocWordConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ import {
type PandocLimits,
type PandocRunError,
} from "./pandocProcess.ts";
import {
applyFontSpans,
applyLatexFontSpans,
latexBaseFontOf,
rewriteLatexSizeGroups,
wordBaseFontOf,
} from "./pandocFont.ts";
import { securePandocDocument } from "./pandocResources.ts";
import { spaceTextAroundTables } from "./pandocTableSpacing.ts";
import { scientReferenceDocument } from "./scientReferenceDocument.ts";
import { scientReferenceDocumentFor, type WordLocalFont } from "./scientReferenceDocument.ts";
import type { PreparedLatexProject } from "./latexProjectPreparation.ts";
import type { CapturedWorkspaceImage } from "./wordImageSnapshot.ts";

Expand Down Expand Up @@ -323,7 +330,7 @@ const make = Effect.gen(function* () {
input.latex
? ["--sandbox", "-f", "latex", "-t", "json"]
: ["--sandbox", "--preserve-tabs", "-f", SCIENT_PANDOC_READER, "-t", "json"],
new TextEncoder().encode(source),
new TextEncoder().encode(input.latex ? rewriteLatexSizeGroups(source) : source),
readLimits,
);
const decoded = yield* decodePandocDocument(new TextDecoder().decode(read.stdout)).pipe(
Expand Down Expand Up @@ -368,6 +375,11 @@ const make = Effect.gen(function* () {
}
}
const citations = applyCitations(document.blocks, bibliography);
// Read before the security pass, which clears the document's metadata.
const baseFont = input.latex ? latexBaseFontOf(source) : wordBaseFontOf(document.meta);
const fontPass = { base: baseFont, used: new Map<string, WordLocalFont>() };
if (input.latex) applyLatexFontSpans(document.blocks, fontPass);
else applyFontSpans(document.blocks, fontPass);
const security = yield* securePandocDocument(document, {
assets: input.bundle.assets,
files: input.imageSnapshot === undefined ? (input.files ?? null) : null,
Expand Down Expand Up @@ -407,7 +419,7 @@ const make = Effect.gen(function* () {
const args = ["--sandbox", "-f", "json", "-t", "docx", "--reference-doc=reference.docx"];
yield* fileSystem.writeFile(
path.join(scratch.work, "reference.docx"),
yield* scientReferenceDocument,
yield* scientReferenceDocumentFor(baseFont, [...fontPass.used.values()]),
);
const cited = [...citations.citedKeys].flatMap((key) => {
const item = bibliography.get(key);
Expand Down
Loading
Loading