feat(md-print): add A4/A5 multi-column print layout

Add an md-print element that paginates markdown into A4 landscape sheets holding two A5 pages, each with configurable columns. The preview modal exports through the browser print dialog.

Paragraphs, lists, and tables split at word, item, and row boundaries; headings are kept with following content.
This commit is contained in:
2026-10-23 11:00:59 +08:00
parent bd7871a800
commit 4a19336445
17 changed files with 1523 additions and 1 deletions
+52
View File
@@ -0,0 +1,52 @@
import { normalizePrintConfig, PRINT_DEFAULTS } from "./config";
describe("normalizePrintConfig", () => {
test("uses defaults", () => {
expect(normalizePrintConfig()).toEqual(PRINT_DEFAULTS);
});
test("parses directive strings and clamps values", () => {
const config = normalizePrintConfig({
columns: "3",
margin: "100",
gap: "-5",
font: "20",
pageNumbers: "false",
cutMarks: "no",
});
expect(config.columns).toBe(3);
expect(config.margin).toBe(40);
expect(config.gap).toBe(0);
expect(config.font).toBe(16);
expect(config.pageNumbers).toBe(false);
expect(config.cutMarks).toBe(false);
});
test("clamps columns to 1..4", () => {
expect(normalizePrintConfig({ columns: "0" }).columns).toBe(1);
expect(normalizePrintConfig({ columns: "9" }).columns).toBe(4);
});
test("accepts YAML data-config numbers and booleans", () => {
const config = normalizePrintConfig({
columns: 2,
margin: 12,
gap: 6,
font: 10,
title: "规则书",
pageNumbers: true,
cutMarks: false,
});
expect(config).toEqual({
columns: 2,
margin: 12,
gap: 6,
font: 10,
title: "规则书",
pageNumbers: true,
cutMarks: false,
});
});
});