markdown-to-word 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/build/docx-font-preset.d.ts +29 -3
- package/build/docx-font-preset.js +261 -13
- package/build/docx-font-preset.js.map +1 -1
- package/build/font-presets.d.ts +37 -0
- package/build/font-presets.js +19 -0
- package/build/font-presets.js.map +1 -1
- package/build/main.d.ts +1 -1
- package/build/main.js +1 -1
- package/build/main.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -57,7 +57,10 @@ The preset also sets the page:
|
|
|
57
57
|
|
|
58
58
|
- **Paper and margins (5.1, 5.2.1):** A4, with a 37mm top margin (天头) and a 28mm left margin (订口) around a 156 × 225mm text block (版心).
|
|
59
59
|
- **22 lines of 28 characters (5.2.3):** a Word document grid (文档网格) with exact line spacing at its pitch, 28.95pt. Widow control (孤行控制) is off, so it can't push a line to the next page and leave 21.
|
|
60
|
-
- **Indent (7.3.3):** paragraphs, and the headings below the title, start two characters in (首行缩进 2 字符). Table cells
|
|
60
|
+
- **Indent (7.3.3):** paragraphs, and the headings below the title, start two characters in (首行缩进 2 字符). Table cells and code blocks don't.
|
|
61
|
+
- **Lists:** every level of an ordered or unordered list is laid out like a 公文 paragraph — the item's first line starts two characters in (首行缩进 2 字符) and one space, not a tab, separates the mark from its content (编号与内容的间距: 适中). Ordered levels stay flush with the text block (文本之前 0) at every depth, which is what a 公文 does: its numbering text already shows the level. Bulleted levels step out by two characters per level so nesting is visible, and each level gets its own bullet, as Word's multi-level library does: ● then ○ then ▪, repeated for deeper levels, drawn in the body font.
|
|
62
|
+
- **Multi-level numbering (opt-in):** the **Chinese official document (公文), 1.1 numbering** style additionally counts nested numbers through their parent, so the second item of the third item reads `3.2`. GB/T 9704-2012 §7.3.3 numbers levels 一、 (一) 1. (1) rather than 1.1, so this is a separate choice for contracts and similar instruments: it points every level of one list at a single numbering definition (`w:numId`) and rewrites the level text to `%1.`, `%1.%2.`, `%1.%2.%3.`. Separate lists keep separate counters, and a bullet nested inside a numbered list keeps its own definition.
|
|
63
|
+
- **Tables:** cells are centered vertically (垂直对齐: 居中) and their paragraphs use single line spacing with grid snapping off (取消"如果定义了文档网格,则与网格对齐"). The page grid's exact 28.95pt pitch would stretch every row and clip text that wraps, so cells stay outside it.
|
|
61
64
|
- **Title (7.3.1):** Heading 1 is centered.
|
|
62
65
|
- **Spacing:** 段前段后 0 行 on every level.
|
|
63
66
|
|
|
@@ -117,7 +120,7 @@ npm install -g markdown-to-word
|
|
|
117
120
|
md2w report.md
|
|
118
121
|
```
|
|
119
122
|
|
|
120
|
-
It writes the `.docx` next to the input with the same name (`report.md` becomes `report.docx`), replacing any file already there, and prints where it wrote it to **stderr**. It needs Node 22.
|
|
123
|
+
It writes the `.docx` next to the input with the same name (`report.md` becomes `report.docx`), replacing any file already there, and prints where it wrote it to **stderr**. It needs Node 22.22.2+, 24.15+, or 26+, and exits with status 1 and a message if the file is missing or empty.
|
|
121
124
|
|
|
122
125
|
To read the Markdown from **stdin**, pass `-` as the file, or leave it out and pipe the Markdown in. There's no file name to go on then, so `-o` is required:
|
|
123
126
|
|
|
@@ -129,7 +132,7 @@ md2w - -o - < report.md > report.docx
|
|
|
129
132
|
Options:
|
|
130
133
|
|
|
131
134
|
- `-o, --output <file>`: write the `.docx` to `<file>`, creating folders as needed. `-o -` writes it to stdout.
|
|
132
|
-
- `--font-preset <name>`: restyle the document with a font preset. `chinese-official` is the Chinese official document (公文) style described in [Optional Font Presets](#optional-font-presets).
|
|
135
|
+
- `--font-preset <name>`: restyle the document with a font preset. `chinese-official` is the Chinese official document (公文) style described in [Optional Font Presets](#optional-font-presets); `chinese-official-multilevel` adds the `1.1` numbering for contracts.
|
|
133
136
|
- `-q, --quiet`: print nothing to stderr except errors.
|
|
134
137
|
- `-V, --version`: print the version.
|
|
135
138
|
|
|
@@ -163,7 +166,7 @@ It has one tool, `convert_markdown_to_word`:
|
|
|
163
166
|
- `markdown` or `path` (exactly one): the Markdown as a string, or the path of a Markdown file (`.md`, `.markdown`, `.mdown`, or `.txt`). Prefer absolute paths; relative ones resolve against the server's working directory.
|
|
164
167
|
- `output_path` (required): where to write the `.docx`; it must end in `.docx`. Missing folders are created.
|
|
165
168
|
- `overwrite`: replace `output_path` if it already exists. Off by default, so the tool refuses to clobber an existing file and says so.
|
|
166
|
-
- `font_preset`: `chinese-official` for the 公文 style; omit for Word's default styling.
|
|
169
|
+
- `font_preset`: `chinese-official` for the 公文 style, `chinese-official-multilevel` for 公文 plus `1.1` numbering; omit for Word's default styling.
|
|
167
170
|
|
|
168
171
|
It returns the `output_path`, the file's size in `bytes`, and any `warnings` (remote images it didn't download, or a `.docx` patch that had to be skipped), also as structured content.
|
|
169
172
|
|
|
@@ -173,7 +176,7 @@ In the browser, md2word.app registers the same conversion as a [WebMCP](https://
|
|
|
173
176
|
|
|
174
177
|
## Use it from code
|
|
175
178
|
|
|
176
|
-
The converter is also on npm as [`markdown-to-word`](https://www.npmjs.com/package/markdown-to-word), for Node 22.
|
|
179
|
+
The converter is also on npm as [`markdown-to-word`](https://www.npmjs.com/package/markdown-to-word), for Node 22.22.2+, 24.15+, or 26+, and for browsers through a bundler (Vite, webpack, esbuild):
|
|
177
180
|
|
|
178
181
|
```bash
|
|
179
182
|
npm install markdown-to-word
|
|
@@ -201,7 +204,7 @@ On a server, treat Markdown from users as untrusted: the converter downloads eac
|
|
|
201
204
|
|
|
202
205
|
## Development
|
|
203
206
|
|
|
204
|
-
Requires Node.js 22.
|
|
207
|
+
Requires Node.js 22.22.2+, 24.15+, or 26+ (`.nvmrc` pins the version CI uses).
|
|
205
208
|
|
|
206
209
|
```bash
|
|
207
210
|
git clone https://github.com/benbalter/markdown-to-word-js.git
|
|
@@ -7,8 +7,8 @@ interface Grid {
|
|
|
7
7
|
charSpace: number;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Rewrites the fonts, sizes, paragraph spacing
|
|
11
|
-
* generated .docx.
|
|
10
|
+
* Rewrites the fonts, sizes, paragraph spacing, page grid and list layout of an
|
|
11
|
+
* already generated .docx.
|
|
12
12
|
*
|
|
13
13
|
* `html-to-docx` only ever writes `w:ascii`, which WinWord applies to Latin
|
|
14
14
|
* characters and digits; Chinese characters fall back to the theme font. The
|
|
@@ -37,9 +37,35 @@ export declare function patchStylesXml(stylesXml: string, preset: FontPreset, gr
|
|
|
37
37
|
* with a drawing keep single spacing; the grid then rounds them up to whole
|
|
38
38
|
* lines.
|
|
39
39
|
* - Table cells drop the first-line indent; it only crowds narrow columns.
|
|
40
|
+
* - When the preset describes table cells, they are laid out on their own
|
|
41
|
+
* terms instead of inheriting the page grid: vertical alignment, line
|
|
42
|
+
* spacing and grid snapping.
|
|
40
43
|
*/
|
|
41
|
-
export declare function patchDocumentXml(documentXml: string, preset: FontPreset): {
|
|
44
|
+
export declare function patchDocumentXml(documentXml: string, preset: FontPreset, formats?: NumberFormats): {
|
|
42
45
|
xml: string;
|
|
43
46
|
grid: Grid | null;
|
|
44
47
|
};
|
|
48
|
+
/** The number format a numbering definition uses at each level. */
|
|
49
|
+
export type NumberFormats = ReadonlyMap<string, string[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Lays out lists the way a 公文 does, in the place Word itself writes these
|
|
52
|
+
* choices — the numbering definitions:
|
|
53
|
+
*
|
|
54
|
+
* - 首行缩进 N 字符: the item's first line is indented by the preset's
|
|
55
|
+
* `firstLineIndentChars`, written as `w:firstLineChars` so Word shows it in
|
|
56
|
+
* characters and it scales with the font size.
|
|
57
|
+
* - 编号与内容的间距 适中: `w:suff` is `space`, so one space separates the
|
|
58
|
+
* number or bullet from its content instead of a tab.
|
|
59
|
+
* - 文本之前: ordered levels sit flush with the text block at every level, the
|
|
60
|
+
* way a printed 公文 numbers its items (1. (1) ① all start from the same
|
|
61
|
+
* margin). Bulleted levels instead step out by the preset's indent each
|
|
62
|
+
* level, because a bullet carries no hierarchy of its own.
|
|
63
|
+
* - one bullet per nesting level, ● then ○ then ▪.
|
|
64
|
+
*
|
|
65
|
+
* Numbering itself is left alone: ordered levels keep the generator's
|
|
66
|
+
* `%1.` / `%2.` text. The level's tab stop stays where it is, so a renderer
|
|
67
|
+
* that ignores `w:suff` still puts the content near the indent rather than on
|
|
68
|
+
* top of the mark.
|
|
69
|
+
*/
|
|
70
|
+
export declare function patchNumberingXml(numberingXml: string, preset: FontPreset): string;
|
|
45
71
|
export {};
|
|
@@ -13,8 +13,8 @@ const THEME_FONT_ATTRIBUTES = [
|
|
|
13
13
|
*/
|
|
14
14
|
const SINGLE_SPACING = { line: '240', rule: 'auto' };
|
|
15
15
|
/**
|
|
16
|
-
* Rewrites the fonts, sizes, paragraph spacing
|
|
17
|
-
* generated .docx.
|
|
16
|
+
* Rewrites the fonts, sizes, paragraph spacing, page grid and list layout of an
|
|
17
|
+
* already generated .docx.
|
|
18
18
|
*
|
|
19
19
|
* `html-to-docx` only ever writes `w:ascii`, which WinWord applies to Latin
|
|
20
20
|
* characters and digits; Chinese characters fall back to the theme font. The
|
|
@@ -30,22 +30,36 @@ export async function applyFontPreset(wordDocument, preset) {
|
|
|
30
30
|
if (!stylesEntry) {
|
|
31
31
|
throw new Error('Cannot apply font preset: document contains no word/styles.xml');
|
|
32
32
|
}
|
|
33
|
+
// The numbering part is read first: laying the document's lists out needs to
|
|
34
|
+
// know which format each numbering definition uses at each level.
|
|
35
|
+
const numberingEntry = zip.file('word/numbering.xml');
|
|
36
|
+
const numberingXml = numberingEntry
|
|
37
|
+
? await numberingEntry.async('string')
|
|
38
|
+
: null;
|
|
39
|
+
const formats = numberingXml ? numberFormatsOf(numberingXml) : undefined;
|
|
33
40
|
let grid = null;
|
|
34
41
|
const pageGrid = preset.page?.grid;
|
|
35
42
|
if (pageGrid ||
|
|
36
43
|
preset.paragraph.lineSpacing === 'grid' ||
|
|
37
|
-
preset.paragraph.firstLineIndentChars
|
|
44
|
+
preset.paragraph.firstLineIndentChars ||
|
|
45
|
+
preset.list?.multilevelNumbers ||
|
|
46
|
+
preset.table) {
|
|
38
47
|
const documentEntry = zip.file('word/document.xml');
|
|
39
48
|
if (!documentEntry) {
|
|
40
49
|
throw new Error('Cannot apply font preset: document contains no word/document.xml');
|
|
41
50
|
}
|
|
42
51
|
const documentXml = await documentEntry.async('string');
|
|
43
|
-
const patched = patchDocumentXml(documentXml, preset);
|
|
52
|
+
const patched = patchDocumentXml(documentXml, preset, formats);
|
|
44
53
|
grid = patched.grid;
|
|
45
54
|
zip.file('word/document.xml', patched.xml);
|
|
46
55
|
}
|
|
47
56
|
const stylesXml = await stylesEntry.async('string');
|
|
48
57
|
zip.file('word/styles.xml', patchStylesXml(stylesXml, preset, grid));
|
|
58
|
+
// Lists are laid out only when the preset describes them; a document
|
|
59
|
+
// without lists has no numbering part anyway.
|
|
60
|
+
if (numberingXml !== null && preset.list) {
|
|
61
|
+
zip.file('word/numbering.xml', patchNumberingXml(numberingXml, preset));
|
|
62
|
+
}
|
|
49
63
|
const patched = await zip.generateAsync({ type: 'arraybuffer' });
|
|
50
64
|
return new Blob([patched], { type: wordDocument.type });
|
|
51
65
|
}
|
|
@@ -76,16 +90,21 @@ export function patchStylesXml(stylesXml, preset, grid = null) {
|
|
|
76
90
|
}
|
|
77
91
|
function resolveLayout(preset, grid) {
|
|
78
92
|
const { lineSpacing, firstLineIndentChars = 0 } = preset.paragraph;
|
|
79
|
-
if (lineSpacing === 'grid' && !grid) {
|
|
80
|
-
throw new Error("Cannot apply font preset: lineSpacing 'grid' needs page.grid");
|
|
81
|
-
}
|
|
82
93
|
return {
|
|
83
|
-
spacing: lineSpacing
|
|
84
|
-
? { line: String(grid.linePitch), rule: 'exact' }
|
|
85
|
-
: SINGLE_SPACING,
|
|
94
|
+
spacing: spacingFor(lineSpacing, grid),
|
|
86
95
|
firstLineIndent: Math.round(firstLineIndentChars * preset.body.sizePt * 20),
|
|
87
96
|
};
|
|
88
97
|
}
|
|
98
|
+
/** The `<w:spacing>` pair a line-spacing choice resolves to on this page. */
|
|
99
|
+
function spacingFor(lineSpacing, grid) {
|
|
100
|
+
if (lineSpacing !== 'grid') {
|
|
101
|
+
return SINGLE_SPACING;
|
|
102
|
+
}
|
|
103
|
+
if (!grid) {
|
|
104
|
+
throw new Error("Cannot apply font preset: lineSpacing 'grid' needs page.grid");
|
|
105
|
+
}
|
|
106
|
+
return { line: String(grid.linePitch), rule: 'exact' };
|
|
107
|
+
}
|
|
89
108
|
/**
|
|
90
109
|
* Sets the page grid in the section properties of a document.xml part, and
|
|
91
110
|
* fixes up the paragraphs that the style-level layout would break:
|
|
@@ -98,9 +117,15 @@ function resolveLayout(preset, grid) {
|
|
|
98
117
|
* with a drawing keep single spacing; the grid then rounds them up to whole
|
|
99
118
|
* lines.
|
|
100
119
|
* - Table cells drop the first-line indent; it only crowds narrow columns.
|
|
120
|
+
* - When the preset describes table cells, they are laid out on their own
|
|
121
|
+
* terms instead of inheriting the page grid: vertical alignment, line
|
|
122
|
+
* spacing and grid snapping.
|
|
101
123
|
*/
|
|
102
|
-
export function patchDocumentXml(documentXml, preset) {
|
|
124
|
+
export function patchDocumentXml(documentXml, preset, formats) {
|
|
103
125
|
const dom = new DOMParser().parseFromString(documentXml, 'application/xml');
|
|
126
|
+
if (preset.list?.multilevelNumbers && formats) {
|
|
127
|
+
unifyListNumbering(dom, formats);
|
|
128
|
+
}
|
|
104
129
|
let grid = null;
|
|
105
130
|
const pageGrid = preset.page?.grid;
|
|
106
131
|
if (pageGrid) {
|
|
@@ -110,9 +135,11 @@ export function patchDocumentXml(documentXml, preset) {
|
|
|
110
135
|
}
|
|
111
136
|
}
|
|
112
137
|
const gridSpacing = preset.paragraph.lineSpacing === 'grid';
|
|
138
|
+
const table = preset.table;
|
|
113
139
|
for (const paragraph of Array.from(dom.getElementsByTagNameNS(W_NS, 'p'))) {
|
|
114
140
|
const pPr = children(paragraph).find((child) => child.localName === 'pPr');
|
|
115
|
-
|
|
141
|
+
const inTableCell = isInTableCell(paragraph);
|
|
142
|
+
if (gridSpacing && !inTableCell) {
|
|
116
143
|
if (paragraph.getElementsByTagNameNS(W_NS, 'drawing').length > 0) {
|
|
117
144
|
const spacing = paragraphProperty(pPrOf(paragraph), 'spacing');
|
|
118
145
|
spacing.setAttributeNS(W_NS, 'w:line', SINGLE_SPACING.line);
|
|
@@ -128,15 +155,236 @@ export function patchDocumentXml(documentXml, preset) {
|
|
|
128
155
|
}
|
|
129
156
|
}
|
|
130
157
|
}
|
|
131
|
-
if (
|
|
158
|
+
if (table && inTableCell) {
|
|
159
|
+
layoutTableCell(pPrOf(paragraph), table, grid);
|
|
160
|
+
}
|
|
161
|
+
if (preset.paragraph.firstLineIndentChars && inTableCell) {
|
|
132
162
|
removeFirstLineIndent(pPrOf(paragraph));
|
|
133
163
|
}
|
|
134
164
|
}
|
|
165
|
+
if (table) {
|
|
166
|
+
for (const cell of Array.from(dom.getElementsByTagNameNS(W_NS, 'tc'))) {
|
|
167
|
+
cellVerticalAlign(cell).setAttributeNS(W_NS, 'w:val', table.verticalAlign);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
135
170
|
return {
|
|
136
171
|
xml: keepXmlDeclaration(documentXml, new XMLSerializer().serializeToString(dom)),
|
|
137
172
|
grid,
|
|
138
173
|
};
|
|
139
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Reads the numbering part into a `numId` → formats map, the way the document's
|
|
177
|
+
* paragraphs reference it. `<w:num>` names an `<w:abstractNum>`, so the
|
|
178
|
+
* abstract's levels answer for the id the paragraphs use.
|
|
179
|
+
*/
|
|
180
|
+
function numberFormatsOf(numberingXml) {
|
|
181
|
+
const dom = new DOMParser().parseFromString(numberingXml, 'application/xml');
|
|
182
|
+
const formatsByAbstract = new Map();
|
|
183
|
+
for (const abstract of Array.from(dom.getElementsByTagNameNS(W_NS, 'abstractNum'))) {
|
|
184
|
+
const abstractId = abstract.getAttributeNS(W_NS, 'abstractNumId');
|
|
185
|
+
if (abstractId === null) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const levels = [];
|
|
189
|
+
for (const lvl of children(abstract).filter((child) => child.localName === 'lvl')) {
|
|
190
|
+
const ilvl = Number(lvl.getAttributeNS(W_NS, 'ilvl') ?? levels.length);
|
|
191
|
+
levels[ilvl] =
|
|
192
|
+
children(lvl)
|
|
193
|
+
.find((child) => child.localName === 'numFmt')
|
|
194
|
+
?.getAttributeNS(W_NS, 'val') ?? '';
|
|
195
|
+
}
|
|
196
|
+
formatsByAbstract.set(abstractId, levels);
|
|
197
|
+
}
|
|
198
|
+
const formats = new Map();
|
|
199
|
+
for (const num of Array.from(dom.getElementsByTagNameNS(W_NS, 'num'))) {
|
|
200
|
+
const numId = num.getAttributeNS(W_NS, 'numId');
|
|
201
|
+
const abstractId = num
|
|
202
|
+
.getElementsByTagNameNS(W_NS, 'abstractNumId')[0]
|
|
203
|
+
?.getAttributeNS(W_NS, 'val');
|
|
204
|
+
const levels = abstractId === null ? undefined : formatsByAbstract.get(abstractId);
|
|
205
|
+
if (numId !== null && levels) {
|
|
206
|
+
formats.set(numId, levels);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return formats;
|
|
210
|
+
}
|
|
211
|
+
/** The `<w:numPr>` of a paragraph, when it has one that names a numbering. */
|
|
212
|
+
function numberingOf(paragraph) {
|
|
213
|
+
const pPr = children(paragraph).find((child) => child.localName === 'pPr');
|
|
214
|
+
const numPr = pPr && children(pPr).find((child) => child.localName === 'numPr');
|
|
215
|
+
if (!numPr) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const numIdElement = children(numPr).find((child) => child.localName === 'numId');
|
|
219
|
+
const numId = numIdElement?.getAttributeNS(W_NS, 'val');
|
|
220
|
+
if (!numIdElement || numId === undefined || numId === null) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
const ilvl = Number(children(numPr)
|
|
224
|
+
.find((child) => child.localName === 'ilvl')
|
|
225
|
+
?.getAttributeNS(W_NS, 'val') ?? '0');
|
|
226
|
+
return { ilvl, numId, numIdElement };
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Word counts a multi-level list inside one numbering definition: its items
|
|
230
|
+
* share a `w:numId` and only `w:ilvl` changes. The generator instead gives
|
|
231
|
+
* every nesting depth its own definition, so a nested item's `%1` is that
|
|
232
|
+
* sub-list's counter rather than its parent's, and 1.1 can never appear.
|
|
233
|
+
*
|
|
234
|
+
* Point the deeper items of a list at the definition its first level uses. A
|
|
235
|
+
* fresh first-level definition opens a new list, so separate lists never share
|
|
236
|
+
* a counter, and a nested level whose format differs from the list's own (a
|
|
237
|
+
* bullet inside a numbered list) keeps its own definition.
|
|
238
|
+
*/
|
|
239
|
+
function unifyListNumbering(dom, formats) {
|
|
240
|
+
let listNumId = null;
|
|
241
|
+
for (const paragraph of Array.from(dom.getElementsByTagNameNS(W_NS, 'p'))) {
|
|
242
|
+
const numbering = numberingOf(paragraph);
|
|
243
|
+
if (!numbering) {
|
|
244
|
+
// A list item's later paragraphs are unnumbered but indented under the
|
|
245
|
+
// item, so only an unindented paragraph ends the list.
|
|
246
|
+
const ind = paragraph.getElementsByTagNameNS(W_NS, 'ind')[0];
|
|
247
|
+
if (Number(ind?.getAttributeNS(W_NS, 'left') ?? 0) <= 0) {
|
|
248
|
+
listNumId = null;
|
|
249
|
+
}
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (numbering.ilvl === 0) {
|
|
253
|
+
listNumId = numbering.numId;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (listNumId === null) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const list = formats.get(listNumId);
|
|
260
|
+
const own = formats.get(numbering.numId);
|
|
261
|
+
if (!list || !own || list[numbering.ilvl] !== own[numbering.ilvl]) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
numbering.numIdElement.setAttributeNS(W_NS, 'w:val', listNumId);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Lays out lists the way a 公文 does, in the place Word itself writes these
|
|
269
|
+
* choices — the numbering definitions:
|
|
270
|
+
*
|
|
271
|
+
* - 首行缩进 N 字符: the item's first line is indented by the preset's
|
|
272
|
+
* `firstLineIndentChars`, written as `w:firstLineChars` so Word shows it in
|
|
273
|
+
* characters and it scales with the font size.
|
|
274
|
+
* - 编号与内容的间距 适中: `w:suff` is `space`, so one space separates the
|
|
275
|
+
* number or bullet from its content instead of a tab.
|
|
276
|
+
* - 文本之前: ordered levels sit flush with the text block at every level, the
|
|
277
|
+
* way a printed 公文 numbers its items (1. (1) ① all start from the same
|
|
278
|
+
* margin). Bulleted levels instead step out by the preset's indent each
|
|
279
|
+
* level, because a bullet carries no hierarchy of its own.
|
|
280
|
+
* - one bullet per nesting level, ● then ○ then ▪.
|
|
281
|
+
*
|
|
282
|
+
* Numbering itself is left alone: ordered levels keep the generator's
|
|
283
|
+
* `%1.` / `%2.` text. The level's tab stop stays where it is, so a renderer
|
|
284
|
+
* that ignores `w:suff` still puts the content near the indent rather than on
|
|
285
|
+
* top of the mark.
|
|
286
|
+
*/
|
|
287
|
+
export function patchNumberingXml(numberingXml, preset) {
|
|
288
|
+
const dom = new DOMParser().parseFromString(numberingXml, 'application/xml');
|
|
289
|
+
const indentChars = preset.paragraph.firstLineIndentChars ?? 0;
|
|
290
|
+
const bullets = preset.list?.bullets ?? [];
|
|
291
|
+
for (const lvl of Array.from(dom.getElementsByTagNameNS(W_NS, 'lvl'))) {
|
|
292
|
+
const format = children(lvl).find((child) => child.localName === 'numFmt');
|
|
293
|
+
const bulleted = format?.getAttributeNS(W_NS, 'val') === 'bullet';
|
|
294
|
+
const level = Number(lvl.getAttributeNS(W_NS, 'ilvl') ?? '0');
|
|
295
|
+
// Only bullets nest by indentation; numbering text already shows the level.
|
|
296
|
+
const indentLevel = bulleted ? level : 0;
|
|
297
|
+
setNumberSeparator(lvl);
|
|
298
|
+
const ind = childOrCreate(numberingParagraphOf(lvl), 'ind', 'last');
|
|
299
|
+
for (const attribute of ['hanging', 'hangingChars', 'firstLine']) {
|
|
300
|
+
ind.removeAttributeNS(W_NS, attribute);
|
|
301
|
+
}
|
|
302
|
+
// One character is the body font size in twips, which is what a renderer
|
|
303
|
+
// that ignores the `*Chars` attributes needs alongside them.
|
|
304
|
+
ind.setAttributeNS(W_NS, 'w:left', String(indentLevel * indentChars * preset.body.sizePt * 20));
|
|
305
|
+
ind.setAttributeNS(W_NS, 'w:leftChars', String(indentLevel * indentChars * 100));
|
|
306
|
+
ind.setAttributeNS(W_NS, 'w:firstLineChars', String(indentChars * 100));
|
|
307
|
+
if (bulleted && bullets.length) {
|
|
308
|
+
setBulletGlyph(lvl, level, bullets, preset.body.eastAsia);
|
|
309
|
+
}
|
|
310
|
+
else if (!bulleted && preset.list?.multilevelNumbers) {
|
|
311
|
+
setMultilevelNumber(lvl, level);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return keepXmlDeclaration(numberingXml, new XMLSerializer().serializeToString(dom));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Gives each nesting level its own bullet, as Word's multi-level library does.
|
|
318
|
+
* The generator repeats one private-use glyph in the Symbol font at every
|
|
319
|
+
* level, so the level's run properties move to the body font, which carries
|
|
320
|
+
* these shapes.
|
|
321
|
+
*/
|
|
322
|
+
function setBulletGlyph(lvl, level, bullets, font) {
|
|
323
|
+
const format = children(lvl).find((child) => child.localName === 'numFmt');
|
|
324
|
+
if (format?.getAttributeNS(W_NS, 'val') !== 'bullet') {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const lvlText = children(lvl).find((child) => child.localName === 'lvlText');
|
|
328
|
+
if (!lvlText) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
lvlText.setAttributeNS(W_NS, 'w:val', bullets[Math.min(level, bullets.length - 1)]);
|
|
332
|
+
const rFonts = childOrCreate(childOrCreate(lvl, 'rPr', 'last'), 'rFonts', 'first');
|
|
333
|
+
for (const attribute of ['ascii', 'hAnsi', 'eastAsia', 'cs']) {
|
|
334
|
+
rFonts.setAttributeNS(W_NS, `w:${attribute}`, font);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Makes a nested number carry its parents: level 0 stays `1.`, level 1 becomes
|
|
339
|
+
* `1.1`, level 2 `1.1.1`. Word restarts a level whenever the one above it
|
|
340
|
+
* moves, which is its default, so the second item of the third item reads 3.2.
|
|
341
|
+
*/
|
|
342
|
+
function setMultilevelNumber(lvl, level) {
|
|
343
|
+
const lvlText = children(lvl).find((child) => child.localName === 'lvlText');
|
|
344
|
+
if (!lvlText) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const parents = Array.from({ length: level }, (_, index) => `%${index + 1}`);
|
|
348
|
+
lvlText.setAttributeNS(W_NS, 'w:val', [...parents, `%${level + 1}.`].join('.'));
|
|
349
|
+
}
|
|
350
|
+
/** `<w:suff>` sits between `<w:isLgl>` and `<w:lvlText>` in a level. */
|
|
351
|
+
function setNumberSeparator(lvl) {
|
|
352
|
+
const existing = children(lvl).find((child) => child.localName === 'suff');
|
|
353
|
+
const suff = existing ?? lvl.ownerDocument.createElementNS(W_NS, 'w:suff');
|
|
354
|
+
if (!existing) {
|
|
355
|
+
const lvlText = children(lvl).find((child) => child.localName === 'lvlText');
|
|
356
|
+
lvl.insertBefore(suff, lvlText ?? null);
|
|
357
|
+
}
|
|
358
|
+
suff.setAttributeNS(W_NS, 'w:val', 'space');
|
|
359
|
+
}
|
|
360
|
+
/** The paragraph properties a numbering level carries, created when absent. */
|
|
361
|
+
function numberingParagraphOf(lvl) {
|
|
362
|
+
return childOrCreate(lvl, 'pPr', 'last');
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Cells sit outside the page grid: exact spacing at the line pitch would
|
|
366
|
+
* stretch every row to a whole pitch and clip what wraps, so a cell paragraph
|
|
367
|
+
* takes its own line spacing and stops snapping to the grid (Word's 如果定义了
|
|
368
|
+
* 文档网格,则与网格对齐 checkbox, `w:snapToGrid`).
|
|
369
|
+
*/
|
|
370
|
+
function layoutTableCell(pPr, table, grid) {
|
|
371
|
+
const spacing = spacingFor(table.lineSpacing, grid);
|
|
372
|
+
const spacingElement = paragraphProperty(pPr, 'spacing');
|
|
373
|
+
spacingElement.setAttributeNS(W_NS, 'w:line', spacing.line);
|
|
374
|
+
spacingElement.setAttributeNS(W_NS, 'w:lineRule', spacing.rule);
|
|
375
|
+
paragraphProperty(pPr, 'snapToGrid').setAttributeNS(W_NS, 'w:val', table.snapToGrid ? '1' : '0');
|
|
376
|
+
}
|
|
377
|
+
/** `<w:vAlign>` in a cell's properties, created where Word writes it. */
|
|
378
|
+
function cellVerticalAlign(cell) {
|
|
379
|
+
const tcPr = childOrCreate(cell, 'tcPr', 'first');
|
|
380
|
+
const existing = children(tcPr).find((child) => child.localName === 'vAlign');
|
|
381
|
+
if (existing) {
|
|
382
|
+
return existing;
|
|
383
|
+
}
|
|
384
|
+
const created = tcPr.ownerDocument.createElementNS(W_NS, 'w:vAlign');
|
|
385
|
+
const hideMark = children(tcPr).find((child) => child.localName === 'hideMark');
|
|
386
|
+
return tcPr.insertBefore(created, hideMark ?? null);
|
|
387
|
+
}
|
|
140
388
|
/**
|
|
141
389
|
* The grid for the text block of `sectPr`'s page. Word stores the character
|
|
142
390
|
* pitch as an offset from the body font size. Both pitches are rounded down,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docx-font-preset.js","sourceRoot":"","sources":["../src/docx-font-preset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,IAAI,IAAI,GAC1B,MAAM,eAAe,CAAC;AAEvB,+DAA+D;AAC/D,MAAM,qBAAqB,GAAG;IAC5B,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,SAAS;CACV,CAAC;A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AED,SAAS,cAAc,CAAC,GAAa,EAAE,SAAiB;IACtD,MAAM,OAAO,GAAG,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,kDAAkD,SAAS,WAAW,CACvE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import JSZip from 'jszip';\nimport type { FontPreset, LevelStyle, ParagraphStyle } from './font-presets.js';\nimport {\n keepXmlDeclaration,\n paragraphProperty,\n WORDPROCESSING_NS as W_NS,\n} from './xml-part.js';\n\n/** Theme slots WinWord prefers over explicitly named fonts. */\nconst THEME_FONT_ATTRIBUTES = [\n 'asciiTheme',\n 'eastAsiaTheme',\n 'hAnsiTheme',\n 'cstheme',\n];\n\n/**\n * `<w:line>` is ignored while the rule is auto, but WinWord still writes 240\n * twips, so the preset writes the pair Word itself produces.\n */\nconst SINGLE_SPACING = { line: '240', rule: 'auto' };\n\n/** Word's document grid, in the units of `<w:docGrid>`. */\ninterface Grid {\n /** Line pitch in twips. */\n linePitch: number;\n /** Character pitch relative to the body font size, in 1/4096 point. */\n charSpace: number;\n}\n\n/** What the styles need to know about the paragraphs, resolved once. */\ninterface Layout {\n spacing: { line: string; rule: string };\n /** First-line indent of body paragraphs in twips, or 0 for none. */\n firstLineIndent: number;\n}\n\n/**\n * Rewrites the fonts, sizes, paragraph spacing and page grid of an already\n * generated .docx.\n *\n * `html-to-docx` only ever writes `w:ascii`, which WinWord applies to Latin\n * characters and digits; Chinese characters fall back to the theme font. The\n * East Asian slots are set here instead, so this stays out of the way of the\n * default conversion output.\n *\n * The grid is measured from the page the document actually has, so it still\n * fits when `pageMargins` overrode the preset's margins.\n */\nexport async function applyFontPreset(\n wordDocument: Blob,\n preset: FontPreset\n): Promise<Blob> {\n const zip = await JSZip.loadAsync(await wordDocument.arrayBuffer());\n const stylesEntry = zip.file('word/styles.xml');\n if (!stylesEntry) {\n throw new Error(\n 'Cannot apply font preset: document contains no word/styles.xml'\n );\n }\n\n let grid: Grid | null = null;\n const pageGrid = preset.page?.grid;\n if (\n pageGrid ||\n preset.paragraph.lineSpacing === 'grid' ||\n preset.paragraph.firstLineIndentChars\n ) {\n const documentEntry = zip.file('word/document.xml');\n if (!documentEntry) {\n throw new Error(\n 'Cannot apply font preset: document contains no word/document.xml'\n );\n }\n const documentXml = await documentEntry.async('string');\n const patched = patchDocumentXml(documentXml, preset);\n grid = patched.grid;\n zip.file('word/document.xml', patched.xml);\n }\n\n const stylesXml = await stylesEntry.async('string');\n zip.file('word/styles.xml', patchStylesXml(stylesXml, preset, grid));\n\n const patched = await zip.generateAsync({ type: 'arraybuffer' });\n return new Blob([patched], { type: wordDocument.type });\n}\n\n/**\n * Applies `preset` to the document default run properties and to the six\n * heading styles of a styles.xml part. `grid` is the page grid that\n * `patchDocumentXml` set, which `lineSpacing: 'grid'` takes its pitch from.\n */\nexport function patchStylesXml(\n stylesXml: string,\n preset: FontPreset,\n grid: Grid | null = null\n): string {\n const dom = new DOMParser().parseFromString(stylesXml, 'application/xml');\n const layout = resolveLayout(preset, grid);\n\n const docDefaults = requireElement(dom, 'docDefaults');\n applyLevelStyle(docDefaults, preset.body, preset.paragraph, layout);\n if (layout.spacing.rule === 'exact') {\n // Widow control pulls a line onto the next page whenever a paragraph would\n // leave a single line behind, so pages would often hold one line fewer\n // than the grid. Word turns it on unless the document says otherwise.\n paragraphProperty(\n paragraphPropertiesOf(docDefaults),\n 'widowControl'\n ).setAttributeNS(W_NS, 'w:val', '0');\n }\n\n const styles = Array.from(dom.getElementsByTagNameNS(W_NS, 'style'));\n for (const style of styles) {\n const heading = /^Heading([1-6])$/.exec(\n style.getAttributeNS(W_NS, 'styleId') ?? ''\n );\n if (heading) {\n applyLevelStyle(\n style,\n preset.headings[Number(heading[1]) - 1],\n preset.paragraph,\n layout\n );\n }\n }\n\n return keepXmlDeclaration(\n stylesXml,\n new XMLSerializer().serializeToString(dom)\n );\n}\n\nfunction resolveLayout(preset: FontPreset, grid: Grid | null): Layout {\n const { lineSpacing, firstLineIndentChars = 0 } = preset.paragraph;\n if (lineSpacing === 'grid' && !grid) {\n throw new Error(\n \"Cannot apply font preset: lineSpacing 'grid' needs page.grid\"\n );\n }\n return {\n spacing:\n lineSpacing === 'grid' && grid\n ? { line: String(grid.linePitch), rule: 'exact' }\n : SINGLE_SPACING,\n firstLineIndent: Math.round(firstLineIndentChars * preset.body.sizePt * 20),\n };\n}\n\n/**\n * Sets the page grid in the section properties of a document.xml part, and\n * fixes up the paragraphs that the style-level layout would break:\n *\n * - The generator gives every paragraph `<w:spacing w:lineRule=\"auto\"/>`.\n * Spacing attributes inherit one at a time, so that lone `auto` combined\n * with the style's exact line height would read as a multiple of 240 twips\n * (about 2.4 lines). It is dropped when the preset uses grid spacing.\n * - Exact line spacing would crop an inline image to one line, so paragraphs\n * with a drawing keep single spacing; the grid then rounds them up to whole\n * lines.\n * - Table cells drop the first-line indent; it only crowds narrow columns.\n */\nexport function patchDocumentXml(\n documentXml: string,\n preset: FontPreset\n): { xml: string; grid: Grid | null } {\n const dom = new DOMParser().parseFromString(documentXml, 'application/xml');\n\n let grid: Grid | null = null;\n const pageGrid = preset.page?.grid;\n if (pageGrid) {\n for (const sectPr of Array.from(\n dom.getElementsByTagNameNS(W_NS, 'sectPr')\n )) {\n grid = measureGrid(sectPr, pageGrid, preset.body.sizePt);\n setDocGrid(sectPr, grid);\n }\n }\n\n const gridSpacing = preset.paragraph.lineSpacing === 'grid';\n for (const paragraph of Array.from(dom.getElementsByTagNameNS(W_NS, 'p'))) {\n const pPr = children(paragraph).find((child) => child.localName === 'pPr');\n\n if (gridSpacing) {\n if (paragraph.getElementsByTagNameNS(W_NS, 'drawing').length > 0) {\n const spacing = paragraphProperty(pPrOf(paragraph), 'spacing');\n spacing.setAttributeNS(W_NS, 'w:line', SINGLE_SPACING.line);\n spacing.setAttributeNS(W_NS, 'w:lineRule', SINGLE_SPACING.rule);\n } else {\n const spacing =\n pPr && children(pPr).find((child) => child.localName === 'spacing');\n if (spacing && !spacing.hasAttributeNS(W_NS, 'line')) {\n spacing.removeAttributeNS(W_NS, 'lineRule');\n if (spacing.attributes.length === 0) {\n spacing.remove();\n }\n }\n }\n }\n\n if (preset.paragraph.firstLineIndentChars && isInTableCell(paragraph)) {\n removeFirstLineIndent(pPrOf(paragraph));\n }\n }\n\n return {\n xml: keepXmlDeclaration(\n documentXml,\n new XMLSerializer().serializeToString(dom)\n ),\n grid,\n };\n}\n\n/**\n * The grid for the text block of `sectPr`'s page. Word stores the character\n * pitch as an offset from the body font size. Both pitches are rounded down,\n * as Word does, so the lines and characters always fit: for the page Word\n * itself sets up with GB/T 9704 margins, this reproduces its linePitch=\"579\"\n * and charSpace=\"-834\".\n */\nfunction measureGrid(\n sectPr: Element,\n {\n linesPerPage,\n charsPerLine,\n }: { linesPerPage: number; charsPerLine: number },\n bodySizePt: number\n): Grid {\n const pgSz = children(sectPr).find((child) => child.localName === 'pgSz');\n const pgMar = children(sectPr).find((child) => child.localName === 'pgMar');\n const twips = (element: Element | undefined, attribute: string): number => {\n const value = Number(element?.getAttributeNS(W_NS, attribute));\n if (!Number.isFinite(value) || value <= 0) {\n throw new Error(\n `Cannot apply font preset: section has no page ${attribute}`\n );\n }\n return value;\n };\n\n const textHeight =\n twips(pgSz, 'h') - twips(pgMar, 'top') - twips(pgMar, 'bottom');\n const textWidth =\n twips(pgSz, 'w') - twips(pgMar, 'left') - twips(pgMar, 'right');\n const charPitchPt = textWidth / 20 / charsPerLine;\n\n return {\n linePitch: Math.floor(textHeight / linesPerPage),\n charSpace: Math.floor((charPitchPt - bodySizePt) * 4096),\n };\n}\n\nfunction setDocGrid(sectPr: Element, grid: Grid): void {\n let docGrid = children(sectPr).find((child) => child.localName === 'docGrid');\n if (!docGrid) {\n docGrid = sectPr.ownerDocument.createElementNS(W_NS, 'w:docGrid');\n // <w:docGrid> is the last section property but <w:printerSettings>.\n const printerSettings = children(sectPr).find(\n (child) => child.localName === 'printerSettings'\n );\n sectPr.insertBefore(docGrid, printerSettings ?? null);\n }\n docGrid.setAttributeNS(W_NS, 'w:type', 'linesAndChars');\n docGrid.setAttributeNS(W_NS, 'w:linePitch', String(grid.linePitch));\n docGrid.setAttributeNS(W_NS, 'w:charSpace', String(grid.charSpace));\n}\n\nfunction isInTableCell(paragraph: Element): boolean {\n for (let node = paragraph.parentElement; node; node = node.parentElement) {\n if (node.namespaceURI === W_NS && node.localName === 'tc') {\n return true;\n }\n }\n return false;\n}\n\nfunction removeFirstLineIndent(pPr: Element): void {\n const ind = paragraphProperty(pPr, 'ind');\n if (!ind.hasAttributeNS(W_NS, 'hanging')) {\n ind.setAttributeNS(W_NS, 'w:firstLine', '0');\n }\n}\n\n/** A paragraph's `<w:pPr>`, created as its first child if missing. */\nfunction pPrOf(paragraph: Element): Element {\n return childOrCreate(paragraph, 'pPr', 'first');\n}\n\nfunction applyLevelStyle(\n scope: Element,\n style: LevelStyle,\n paragraph: ParagraphStyle,\n layout: Layout\n): void {\n const rPr = runPropertiesOf(scope);\n\n const rFonts = childOrCreate(rPr, 'rFonts', 'first');\n for (const attribute of THEME_FONT_ATTRIBUTES) {\n rFonts.removeAttributeNS(W_NS, attribute);\n }\n rFonts.setAttributeNS(W_NS, 'w:ascii', style.latin);\n rFonts.setAttributeNS(W_NS, 'w:hAnsi', style.latin);\n rFonts.setAttributeNS(W_NS, 'w:eastAsia', style.eastAsia);\n\n for (const child of children(rPr)) {\n if (child.localName === 'b' || child.localName === 'bCs') {\n child.remove();\n }\n }\n if (style.bold) {\n rPr.insertBefore(\n rPr.ownerDocument.createElementNS(W_NS, 'w:b'),\n rFonts.nextSibling\n );\n }\n\n // <w:sz> is measured in half points.\n const size = String(style.sizePt * 2);\n childOrCreate(rPr, 'sz', 'last').setAttributeNS(W_NS, 'w:val', size);\n childOrCreate(rPr, 'szCs', 'last').setAttributeNS(W_NS, 'w:val', size);\n\n const pPr = paragraphPropertiesOf(scope);\n const spacing = paragraphProperty(pPr, 'spacing');\n spacing.setAttributeNS(W_NS, 'w:before', String(paragraph.beforePt * 20));\n spacing.setAttributeNS(W_NS, 'w:after', String(paragraph.afterPt * 20));\n spacing.setAttributeNS(W_NS, 'w:line', layout.spacing.line);\n spacing.setAttributeNS(W_NS, 'w:lineRule', layout.spacing.rule);\n\n if (style.centered) {\n // An indented first line would push a centered title off center.\n if (layout.firstLineIndent) {\n paragraphProperty(pPr, 'ind').setAttributeNS(W_NS, 'w:firstLine', '0');\n }\n paragraphProperty(pPr, 'jc').setAttributeNS(W_NS, 'w:val', 'center');\n } else if (layout.firstLineIndent) {\n paragraphProperty(pPr, 'ind').setAttributeNS(\n W_NS,\n 'w:firstLine',\n String(layout.firstLineIndent)\n );\n }\n}\n\nfunction runPropertiesOf(parent: Element): Element {\n const container =\n parent.localName === 'docDefaults'\n ? childOrCreate(parent, 'rPrDefault', 'first')\n : parent;\n // In a <w:style> the run properties go last, after any <w:pPr>.\n return childOrCreate(container, 'rPr', 'last');\n}\n\nfunction paragraphPropertiesOf(parent: Element): Element {\n if (parent.localName === 'docDefaults') {\n const pPrDefault = childOrCreate(parent, 'pPrDefault', 'last');\n return childOrCreate(pPrDefault, 'pPr', 'first');\n }\n\n const existing = children(parent).find((child) => child.localName === 'pPr');\n if (existing) {\n return existing;\n }\n // In a <w:style> the paragraph properties go before the run properties.\n const created = parent.ownerDocument.createElementNS(W_NS, 'w:pPr');\n return parent.insertBefore(created, runPropertiesOf(parent));\n}\n\nfunction children(element: Element): Element[] {\n return Array.from(element.children).filter(\n (child) => child.namespaceURI === W_NS\n );\n}\n\nfunction childOrCreate(\n parent: Element,\n localName: string,\n position: 'first' | 'last'\n): Element {\n const existing = children(parent).find(\n (child) => child.localName === localName\n );\n if (existing) {\n return existing;\n }\n const created = parent.ownerDocument.createElementNS(W_NS, `w:${localName}`);\n return position === 'first'\n ? parent.insertBefore(created, parent.firstChild)\n : parent.appendChild(created);\n}\n\nfunction requireElement(dom: Document, localName: string): Element {\n const element = dom.getElementsByTagNameNS(W_NS, localName)[0];\n if (!element) {\n throw new Error(\n `Cannot apply font preset: styles.xml has no <w:${localName}> element`\n );\n }\n return element;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"docx-font-preset.js","sourceRoot":"","sources":["../src/docx-font-preset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,IAAI,IAAI,GAC1B,MAAM,eAAe,CAAC;AAEvB,+DAA+D;AAC/D,MAAM,qBAAqB,GAAG;IAC5B,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,SAAS;CACV,CAAC;AAEF;;;GAGG;AACH,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAiBrD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,YAAkB,EAClB,MAAkB;IAElB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAChD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,kEAAkE;IAClE,MAAM,cAAc,GAAG,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,cAAc;QACjC,CAAC,CAAC,MAAM,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC;QACtC,CAAC,CAAC,IAAI,CAAC;IACT,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAA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E,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CACzC,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC,CAAC;IAC7E,OAAO,QAAQ,KAAK,OAAO;QACzB,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC;QACjD,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,cAAc,CAAC,GAAa,EAAE,SAAiB;IACtD,MAAM,OAAO,GAAG,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,kDAAkD,SAAS,WAAW,CACvE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import JSZip from 'jszip';\nimport type {\n FontPreset,\n LevelStyle,\n LineSpacing,\n ParagraphStyle,\n TableStyle,\n} from './font-presets.js';\nimport {\n keepXmlDeclaration,\n paragraphProperty,\n WORDPROCESSING_NS as W_NS,\n} from './xml-part.js';\n\n/** Theme slots WinWord prefers over explicitly named fonts. */\nconst THEME_FONT_ATTRIBUTES = [\n 'asciiTheme',\n 'eastAsiaTheme',\n 'hAnsiTheme',\n 'cstheme',\n];\n\n/**\n * `<w:line>` is ignored while the rule is auto, but WinWord still writes 240\n * twips, so the preset writes the pair Word itself produces.\n */\nconst SINGLE_SPACING = { line: '240', rule: 'auto' };\n\n/** Word's document grid, in the units of `<w:docGrid>`. */\ninterface Grid {\n /** Line pitch in twips. */\n linePitch: number;\n /** Character pitch relative to the body font size, in 1/4096 point. */\n charSpace: number;\n}\n\n/** What the styles need to know about the paragraphs, resolved once. */\ninterface Layout {\n spacing: { line: string; rule: string };\n /** First-line indent of body paragraphs in twips, or 0 for none. */\n firstLineIndent: number;\n}\n\n/**\n * Rewrites the fonts, sizes, paragraph spacing, page grid and list layout of an\n * already generated .docx.\n *\n * `html-to-docx` only ever writes `w:ascii`, which WinWord applies to Latin\n * characters and digits; Chinese characters fall back to the theme font. The\n * East Asian slots are set here instead, so this stays out of the way of the\n * default conversion output.\n *\n * The grid is measured from the page the document actually has, so it still\n * fits when `pageMargins` overrode the preset's margins.\n */\nexport async function applyFontPreset(\n wordDocument: Blob,\n preset: FontPreset\n): Promise<Blob> {\n const zip = await JSZip.loadAsync(await wordDocument.arrayBuffer());\n const stylesEntry = zip.file('word/styles.xml');\n if (!stylesEntry) {\n throw new Error(\n 'Cannot apply font preset: document contains no word/styles.xml'\n );\n }\n\n // The numbering part is read first: laying the document's lists out needs to\n // know which format each numbering definition uses at each level.\n const numberingEntry = zip.file('word/numbering.xml');\n const numberingXml = numberingEntry\n ? await numberingEntry.async('string')\n : null;\n const formats = numberingXml ? numberFormatsOf(numberingXml) : undefined;\n\n let grid: Grid | null = null;\n const pageGrid = preset.page?.grid;\n if (\n pageGrid ||\n preset.paragraph.lineSpacing === 'grid' ||\n preset.paragraph.firstLineIndentChars ||\n preset.list?.multilevelNumbers ||\n preset.table\n ) {\n const documentEntry = zip.file('word/document.xml');\n if (!documentEntry) {\n throw new Error(\n 'Cannot apply font preset: document contains no word/document.xml'\n );\n }\n const documentXml = await documentEntry.async('string');\n const patched = patchDocumentXml(documentXml, preset, formats);\n grid = patched.grid;\n zip.file('word/document.xml', patched.xml);\n }\n\n const stylesXml = await stylesEntry.async('string');\n zip.file('word/styles.xml', patchStylesXml(stylesXml, preset, grid));\n\n // Lists are laid out only when the preset describes them; a document\n // without lists has no numbering part anyway.\n if (numberingXml !== null && preset.list) {\n zip.file('word/numbering.xml', patchNumberingXml(numberingXml, preset));\n }\n\n const patched = await zip.generateAsync({ type: 'arraybuffer' });\n return new Blob([patched], { type: wordDocument.type });\n}\n\n/**\n * Applies `preset` to the document default run properties and to the six\n * heading styles of a styles.xml part. `grid` is the page grid that\n * `patchDocumentXml` set, which `lineSpacing: 'grid'` takes its pitch from.\n */\nexport function patchStylesXml(\n stylesXml: string,\n preset: FontPreset,\n grid: Grid | null = null\n): string {\n const dom = new DOMParser().parseFromString(stylesXml, 'application/xml');\n const layout = resolveLayout(preset, grid);\n\n const docDefaults = requireElement(dom, 'docDefaults');\n applyLevelStyle(docDefaults, preset.body, preset.paragraph, layout);\n if (layout.spacing.rule === 'exact') {\n // Widow control pulls a line onto the next page whenever a paragraph would\n // leave a single line behind, so pages would often hold one line fewer\n // than the grid. Word turns it on unless the document says otherwise.\n paragraphProperty(\n paragraphPropertiesOf(docDefaults),\n 'widowControl'\n ).setAttributeNS(W_NS, 'w:val', '0');\n }\n\n const styles = Array.from(dom.getElementsByTagNameNS(W_NS, 'style'));\n for (const style of styles) {\n const heading = /^Heading([1-6])$/.exec(\n style.getAttributeNS(W_NS, 'styleId') ?? ''\n );\n if (heading) {\n applyLevelStyle(\n style,\n preset.headings[Number(heading[1]) - 1],\n preset.paragraph,\n layout\n );\n }\n }\n\n return keepXmlDeclaration(\n stylesXml,\n new XMLSerializer().serializeToString(dom)\n );\n}\n\nfunction resolveLayout(preset: FontPreset, grid: Grid | null): Layout {\n const { lineSpacing, firstLineIndentChars = 0 } = preset.paragraph;\n return {\n spacing: spacingFor(lineSpacing, grid),\n firstLineIndent: Math.round(firstLineIndentChars * preset.body.sizePt * 20),\n };\n}\n\n/** The `<w:spacing>` pair a line-spacing choice resolves to on this page. */\nfunction spacingFor(\n lineSpacing: LineSpacing,\n grid: Grid | null\n): { line: string; rule: string } {\n if (lineSpacing !== 'grid') {\n return SINGLE_SPACING;\n }\n if (!grid) {\n throw new Error(\n \"Cannot apply font preset: lineSpacing 'grid' needs page.grid\"\n );\n }\n return { line: String(grid.linePitch), rule: 'exact' };\n}\n\n/**\n * Sets the page grid in the section properties of a document.xml part, and\n * fixes up the paragraphs that the style-level layout would break:\n *\n * - The generator gives every paragraph `<w:spacing w:lineRule=\"auto\"/>`.\n * Spacing attributes inherit one at a time, so that lone `auto` combined\n * with the style's exact line height would read as a multiple of 240 twips\n * (about 2.4 lines). It is dropped when the preset uses grid spacing.\n * - Exact line spacing would crop an inline image to one line, so paragraphs\n * with a drawing keep single spacing; the grid then rounds them up to whole\n * lines.\n * - Table cells drop the first-line indent; it only crowds narrow columns.\n * - When the preset describes table cells, they are laid out on their own\n * terms instead of inheriting the page grid: vertical alignment, line\n * spacing and grid snapping.\n */\nexport function patchDocumentXml(\n documentXml: string,\n preset: FontPreset,\n formats?: NumberFormats\n): { xml: string; grid: Grid | null } {\n const dom = new DOMParser().parseFromString(documentXml, 'application/xml');\n\n if (preset.list?.multilevelNumbers && formats) {\n unifyListNumbering(dom, formats);\n }\n\n let grid: Grid | null = null;\n const pageGrid = preset.page?.grid;\n if (pageGrid) {\n for (const sectPr of Array.from(\n dom.getElementsByTagNameNS(W_NS, 'sectPr')\n )) {\n grid = measureGrid(sectPr, pageGrid, preset.body.sizePt);\n setDocGrid(sectPr, grid);\n }\n }\n\n const gridSpacing = preset.paragraph.lineSpacing === 'grid';\n const table = preset.table;\n for (const paragraph of Array.from(dom.getElementsByTagNameNS(W_NS, 'p'))) {\n const pPr = children(paragraph).find((child) => child.localName === 'pPr');\n const inTableCell = isInTableCell(paragraph);\n\n if (gridSpacing && !inTableCell) {\n if (paragraph.getElementsByTagNameNS(W_NS, 'drawing').length > 0) {\n const spacing = paragraphProperty(pPrOf(paragraph), 'spacing');\n spacing.setAttributeNS(W_NS, 'w:line', SINGLE_SPACING.line);\n spacing.setAttributeNS(W_NS, 'w:lineRule', SINGLE_SPACING.rule);\n } else {\n const spacing =\n pPr && children(pPr).find((child) => child.localName === 'spacing');\n if (spacing && !spacing.hasAttributeNS(W_NS, 'line')) {\n spacing.removeAttributeNS(W_NS, 'lineRule');\n if (spacing.attributes.length === 0) {\n spacing.remove();\n }\n }\n }\n }\n\n if (table && inTableCell) {\n layoutTableCell(pPrOf(paragraph), table, grid);\n }\n\n if (preset.paragraph.firstLineIndentChars && inTableCell) {\n removeFirstLineIndent(pPrOf(paragraph));\n }\n }\n\n if (table) {\n for (const cell of Array.from(dom.getElementsByTagNameNS(W_NS, 'tc'))) {\n cellVerticalAlign(cell).setAttributeNS(\n W_NS,\n 'w:val',\n table.verticalAlign\n );\n }\n }\n\n return {\n xml: keepXmlDeclaration(\n documentXml,\n new XMLSerializer().serializeToString(dom)\n ),\n grid,\n };\n}\n\n/** The number format a numbering definition uses at each level. */\nexport type NumberFormats = ReadonlyMap<string, string[]>;\n\n/**\n * Reads the numbering part into a `numId` → formats map, the way the document's\n * paragraphs reference it. `<w:num>` names an `<w:abstractNum>`, so the\n * abstract's levels answer for the id the paragraphs use.\n */\nfunction numberFormatsOf(numberingXml: string): NumberFormats {\n const dom = new DOMParser().parseFromString(numberingXml, 'application/xml');\n const formatsByAbstract = new Map<string, string[]>();\n\n for (const abstract of Array.from(\n dom.getElementsByTagNameNS(W_NS, 'abstractNum')\n )) {\n const abstractId = abstract.getAttributeNS(W_NS, 'abstractNumId');\n if (abstractId === null) {\n continue;\n }\n const levels: string[] = [];\n for (const lvl of children(abstract).filter(\n (child) => child.localName === 'lvl'\n )) {\n const ilvl = Number(lvl.getAttributeNS(W_NS, 'ilvl') ?? levels.length);\n levels[ilvl] =\n children(lvl)\n .find((child) => child.localName === 'numFmt')\n ?.getAttributeNS(W_NS, 'val') ?? '';\n }\n formatsByAbstract.set(abstractId, levels);\n }\n\n const formats = new Map<string, string[]>();\n for (const num of Array.from(dom.getElementsByTagNameNS(W_NS, 'num'))) {\n const numId = num.getAttributeNS(W_NS, 'numId');\n const abstractId = num\n .getElementsByTagNameNS(W_NS, 'abstractNumId')[0]\n ?.getAttributeNS(W_NS, 'val');\n const levels =\n abstractId === null ? undefined : formatsByAbstract.get(abstractId);\n if (numId !== null && levels) {\n formats.set(numId, levels);\n }\n }\n\n return formats;\n}\n\ninterface ParagraphNumbering {\n ilvl: number;\n numId: string;\n numIdElement: Element;\n}\n\n/** The `<w:numPr>` of a paragraph, when it has one that names a numbering. */\nfunction numberingOf(paragraph: Element): ParagraphNumbering | null {\n const pPr = children(paragraph).find((child) => child.localName === 'pPr');\n const numPr =\n pPr && children(pPr).find((child) => child.localName === 'numPr');\n if (!numPr) {\n return null;\n }\n\n const numIdElement = children(numPr).find(\n (child) => child.localName === 'numId'\n );\n const numId = numIdElement?.getAttributeNS(W_NS, 'val');\n if (!numIdElement || numId === undefined || numId === null) {\n return null;\n }\n\n const ilvl = Number(\n children(numPr)\n .find((child) => child.localName === 'ilvl')\n ?.getAttributeNS(W_NS, 'val') ?? '0'\n );\n return { ilvl, numId, numIdElement };\n}\n\n/**\n * Word counts a multi-level list inside one numbering definition: its items\n * share a `w:numId` and only `w:ilvl` changes. The generator instead gives\n * every nesting depth its own definition, so a nested item's `%1` is that\n * sub-list's counter rather than its parent's, and 1.1 can never appear.\n *\n * Point the deeper items of a list at the definition its first level uses. A\n * fresh first-level definition opens a new list, so separate lists never share\n * a counter, and a nested level whose format differs from the list's own (a\n * bullet inside a numbered list) keeps its own definition.\n */\nfunction unifyListNumbering(dom: Document, formats: NumberFormats): void {\n let listNumId: string | null = null;\n\n for (const paragraph of Array.from(dom.getElementsByTagNameNS(W_NS, 'p'))) {\n const numbering = numberingOf(paragraph);\n if (!numbering) {\n // A list item's later paragraphs are unnumbered but indented under the\n // item, so only an unindented paragraph ends the list.\n const ind = paragraph.getElementsByTagNameNS(W_NS, 'ind')[0];\n if (Number(ind?.getAttributeNS(W_NS, 'left') ?? 0) <= 0) {\n listNumId = null;\n }\n continue;\n }\n\n if (numbering.ilvl === 0) {\n listNumId = numbering.numId;\n continue;\n }\n if (listNumId === null) {\n continue;\n }\n\n const list = formats.get(listNumId);\n const own = formats.get(numbering.numId);\n if (!list || !own || list[numbering.ilvl] !== own[numbering.ilvl]) {\n continue;\n }\n numbering.numIdElement.setAttributeNS(W_NS, 'w:val', listNumId);\n }\n}\n\n/**\n * Lays out lists the way a 公文 does, in the place Word itself writes these\n * choices — the numbering definitions:\n *\n * - 首行缩进 N 字符: the item's first line is indented by the preset's\n * `firstLineIndentChars`, written as `w:firstLineChars` so Word shows it in\n * characters and it scales with the font size.\n * - 编号与内容的间距 适中: `w:suff` is `space`, so one space separates the\n * number or bullet from its content instead of a tab.\n * - 文本之前: ordered levels sit flush with the text block at every level, the\n * way a printed 公文 numbers its items (1. (1) ① all start from the same\n * margin). Bulleted levels instead step out by the preset's indent each\n * level, because a bullet carries no hierarchy of its own.\n * - one bullet per nesting level, ● then ○ then ▪.\n *\n * Numbering itself is left alone: ordered levels keep the generator's\n * `%1.` / `%2.` text. The level's tab stop stays where it is, so a renderer\n * that ignores `w:suff` still puts the content near the indent rather than on\n * top of the mark.\n */\nexport function patchNumberingXml(\n numberingXml: string,\n preset: FontPreset\n): string {\n const dom = new DOMParser().parseFromString(numberingXml, 'application/xml');\n const indentChars = preset.paragraph.firstLineIndentChars ?? 0;\n const bullets = preset.list?.bullets ?? [];\n\n for (const lvl of Array.from(dom.getElementsByTagNameNS(W_NS, 'lvl'))) {\n const format = children(lvl).find((child) => child.localName === 'numFmt');\n const bulleted = format?.getAttributeNS(W_NS, 'val') === 'bullet';\n const level = Number(lvl.getAttributeNS(W_NS, 'ilvl') ?? '0');\n // Only bullets nest by indentation; numbering text already shows the level.\n const indentLevel = bulleted ? level : 0;\n\n setNumberSeparator(lvl);\n\n const ind = childOrCreate(numberingParagraphOf(lvl), 'ind', 'last');\n for (const attribute of ['hanging', 'hangingChars', 'firstLine']) {\n ind.removeAttributeNS(W_NS, attribute);\n }\n // One character is the body font size in twips, which is what a renderer\n // that ignores the `*Chars` attributes needs alongside them.\n ind.setAttributeNS(\n W_NS,\n 'w:left',\n String(indentLevel * indentChars * preset.body.sizePt * 20)\n );\n ind.setAttributeNS(\n W_NS,\n 'w:leftChars',\n String(indentLevel * indentChars * 100)\n );\n ind.setAttributeNS(W_NS, 'w:firstLineChars', String(indentChars * 100));\n\n if (bulleted && bullets.length) {\n setBulletGlyph(lvl, level, bullets, preset.body.eastAsia);\n } else if (!bulleted && preset.list?.multilevelNumbers) {\n setMultilevelNumber(lvl, level);\n }\n }\n\n return keepXmlDeclaration(\n numberingXml,\n new XMLSerializer().serializeToString(dom)\n );\n}\n\n/**\n * Gives each nesting level its own bullet, as Word's multi-level library does.\n * The generator repeats one private-use glyph in the Symbol font at every\n * level, so the level's run properties move to the body font, which carries\n * these shapes.\n */\nfunction setBulletGlyph(\n lvl: Element,\n level: number,\n bullets: string[],\n font: string\n): void {\n const format = children(lvl).find((child) => child.localName === 'numFmt');\n if (format?.getAttributeNS(W_NS, 'val') !== 'bullet') {\n return;\n }\n\n const lvlText = children(lvl).find((child) => child.localName === 'lvlText');\n if (!lvlText) {\n return;\n }\n lvlText.setAttributeNS(\n W_NS,\n 'w:val',\n bullets[Math.min(level, bullets.length - 1)]\n );\n\n const rFonts = childOrCreate(\n childOrCreate(lvl, 'rPr', 'last'),\n 'rFonts',\n 'first'\n );\n for (const attribute of ['ascii', 'hAnsi', 'eastAsia', 'cs']) {\n rFonts.setAttributeNS(W_NS, `w:${attribute}`, font);\n }\n}\n\n/**\n * Makes a nested number carry its parents: level 0 stays `1.`, level 1 becomes\n * `1.1`, level 2 `1.1.1`. Word restarts a level whenever the one above it\n * moves, which is its default, so the second item of the third item reads 3.2.\n */\nfunction setMultilevelNumber(lvl: Element, level: number): void {\n const lvlText = children(lvl).find((child) => child.localName === 'lvlText');\n if (!lvlText) {\n return;\n }\n\n const parents = Array.from({ length: level }, (_, index) => `%${index + 1}`);\n lvlText.setAttributeNS(\n W_NS,\n 'w:val',\n [...parents, `%${level + 1}.`].join('.')\n );\n}\n\n/** `<w:suff>` sits between `<w:isLgl>` and `<w:lvlText>` in a level. */\nfunction setNumberSeparator(lvl: Element): void {\n const existing = children(lvl).find((child) => child.localName === 'suff');\n const suff = existing ?? lvl.ownerDocument.createElementNS(W_NS, 'w:suff');\n if (!existing) {\n const lvlText = children(lvl).find(\n (child) => child.localName === 'lvlText'\n );\n lvl.insertBefore(suff, lvlText ?? null);\n }\n suff.setAttributeNS(W_NS, 'w:val', 'space');\n}\n\n/** The paragraph properties a numbering level carries, created when absent. */\nfunction numberingParagraphOf(lvl: Element): Element {\n return childOrCreate(lvl, 'pPr', 'last');\n}\n\n/**\n * Cells sit outside the page grid: exact spacing at the line pitch would\n * stretch every row to a whole pitch and clip what wraps, so a cell paragraph\n * takes its own line spacing and stops snapping to the grid (Word's 如果定义了\n * 文档网格,则与网格对齐 checkbox, `w:snapToGrid`).\n */\nfunction layoutTableCell(\n pPr: Element,\n table: TableStyle,\n grid: Grid | null\n): void {\n const spacing = spacingFor(table.lineSpacing, grid);\n const spacingElement = paragraphProperty(pPr, 'spacing');\n spacingElement.setAttributeNS(W_NS, 'w:line', spacing.line);\n spacingElement.setAttributeNS(W_NS, 'w:lineRule', spacing.rule);\n\n paragraphProperty(pPr, 'snapToGrid').setAttributeNS(\n W_NS,\n 'w:val',\n table.snapToGrid ? '1' : '0'\n );\n}\n\n/** `<w:vAlign>` in a cell's properties, created where Word writes it. */\nfunction cellVerticalAlign(cell: Element): Element {\n const tcPr = childOrCreate(cell, 'tcPr', 'first');\n const existing = children(tcPr).find((child) => child.localName === 'vAlign');\n if (existing) {\n return existing;\n }\n const created = tcPr.ownerDocument.createElementNS(W_NS, 'w:vAlign');\n const hideMark = children(tcPr).find(\n (child) => child.localName === 'hideMark'\n );\n return tcPr.insertBefore(created, hideMark ?? null);\n}\n\n/**\n * The grid for the text block of `sectPr`'s page. Word stores the character\n * pitch as an offset from the body font size. Both pitches are rounded down,\n * as Word does, so the lines and characters always fit: for the page Word\n * itself sets up with GB/T 9704 margins, this reproduces its linePitch=\"579\"\n * and charSpace=\"-834\".\n */\nfunction measureGrid(\n sectPr: Element,\n {\n linesPerPage,\n charsPerLine,\n }: { linesPerPage: number; charsPerLine: number },\n bodySizePt: number\n): Grid {\n const pgSz = children(sectPr).find((child) => child.localName === 'pgSz');\n const pgMar = children(sectPr).find((child) => child.localName === 'pgMar');\n const twips = (element: Element | undefined, attribute: string): number => {\n const value = Number(element?.getAttributeNS(W_NS, attribute));\n if (!Number.isFinite(value) || value <= 0) {\n throw new Error(\n `Cannot apply font preset: section has no page ${attribute}`\n );\n }\n return value;\n };\n\n const textHeight =\n twips(pgSz, 'h') - twips(pgMar, 'top') - twips(pgMar, 'bottom');\n const textWidth =\n twips(pgSz, 'w') - twips(pgMar, 'left') - twips(pgMar, 'right');\n const charPitchPt = textWidth / 20 / charsPerLine;\n\n return {\n linePitch: Math.floor(textHeight / linesPerPage),\n charSpace: Math.floor((charPitchPt - bodySizePt) * 4096),\n };\n}\n\nfunction setDocGrid(sectPr: Element, grid: Grid): void {\n let docGrid = children(sectPr).find((child) => child.localName === 'docGrid');\n if (!docGrid) {\n docGrid = sectPr.ownerDocument.createElementNS(W_NS, 'w:docGrid');\n // <w:docGrid> is the last section property but <w:printerSettings>.\n const printerSettings = children(sectPr).find(\n (child) => child.localName === 'printerSettings'\n );\n sectPr.insertBefore(docGrid, printerSettings ?? null);\n }\n docGrid.setAttributeNS(W_NS, 'w:type', 'linesAndChars');\n docGrid.setAttributeNS(W_NS, 'w:linePitch', String(grid.linePitch));\n docGrid.setAttributeNS(W_NS, 'w:charSpace', String(grid.charSpace));\n}\n\nfunction isInTableCell(paragraph: Element): boolean {\n for (let node = paragraph.parentElement; node; node = node.parentElement) {\n if (node.namespaceURI === W_NS && node.localName === 'tc') {\n return true;\n }\n }\n return false;\n}\n\nfunction removeFirstLineIndent(pPr: Element): void {\n const ind = paragraphProperty(pPr, 'ind');\n if (!ind.hasAttributeNS(W_NS, 'hanging')) {\n ind.setAttributeNS(W_NS, 'w:firstLine', '0');\n }\n}\n\n/** A paragraph's `<w:pPr>`, created as its first child if missing. */\nfunction pPrOf(paragraph: Element): Element {\n return childOrCreate(paragraph, 'pPr', 'first');\n}\n\nfunction applyLevelStyle(\n scope: Element,\n style: LevelStyle,\n paragraph: ParagraphStyle,\n layout: Layout\n): void {\n const rPr = runPropertiesOf(scope);\n\n const rFonts = childOrCreate(rPr, 'rFonts', 'first');\n for (const attribute of THEME_FONT_ATTRIBUTES) {\n rFonts.removeAttributeNS(W_NS, attribute);\n }\n rFonts.setAttributeNS(W_NS, 'w:ascii', style.latin);\n rFonts.setAttributeNS(W_NS, 'w:hAnsi', style.latin);\n rFonts.setAttributeNS(W_NS, 'w:eastAsia', style.eastAsia);\n\n for (const child of children(rPr)) {\n if (child.localName === 'b' || child.localName === 'bCs') {\n child.remove();\n }\n }\n if (style.bold) {\n rPr.insertBefore(\n rPr.ownerDocument.createElementNS(W_NS, 'w:b'),\n rFonts.nextSibling\n );\n }\n\n // <w:sz> is measured in half points.\n const size = String(style.sizePt * 2);\n childOrCreate(rPr, 'sz', 'last').setAttributeNS(W_NS, 'w:val', size);\n childOrCreate(rPr, 'szCs', 'last').setAttributeNS(W_NS, 'w:val', size);\n\n const pPr = paragraphPropertiesOf(scope);\n const spacing = paragraphProperty(pPr, 'spacing');\n spacing.setAttributeNS(W_NS, 'w:before', String(paragraph.beforePt * 20));\n spacing.setAttributeNS(W_NS, 'w:after', String(paragraph.afterPt * 20));\n spacing.setAttributeNS(W_NS, 'w:line', layout.spacing.line);\n spacing.setAttributeNS(W_NS, 'w:lineRule', layout.spacing.rule);\n\n if (style.centered) {\n // An indented first line would push a centered title off center.\n if (layout.firstLineIndent) {\n paragraphProperty(pPr, 'ind').setAttributeNS(W_NS, 'w:firstLine', '0');\n }\n paragraphProperty(pPr, 'jc').setAttributeNS(W_NS, 'w:val', 'center');\n } else if (layout.firstLineIndent) {\n paragraphProperty(pPr, 'ind').setAttributeNS(\n W_NS,\n 'w:firstLine',\n String(layout.firstLineIndent)\n );\n }\n}\n\nfunction runPropertiesOf(parent: Element): Element {\n const container =\n parent.localName === 'docDefaults'\n ? childOrCreate(parent, 'rPrDefault', 'first')\n : parent;\n // In a <w:style> the run properties go last, after any <w:pPr>.\n return childOrCreate(container, 'rPr', 'last');\n}\n\nfunction paragraphPropertiesOf(parent: Element): Element {\n if (parent.localName === 'docDefaults') {\n const pPrDefault = childOrCreate(parent, 'pPrDefault', 'last');\n return childOrCreate(pPrDefault, 'pPr', 'first');\n }\n\n const existing = children(parent).find((child) => child.localName === 'pPr');\n if (existing) {\n return existing;\n }\n // In a <w:style> the paragraph properties go before the run properties.\n const created = parent.ownerDocument.createElementNS(W_NS, 'w:pPr');\n return parent.insertBefore(created, runPropertiesOf(parent));\n}\n\nfunction children(element: Element): Element[] {\n return Array.from(element.children).filter(\n (child) => child.namespaceURI === W_NS\n );\n}\n\nfunction childOrCreate(\n parent: Element,\n localName: string,\n position: 'first' | 'last'\n): Element {\n const existing = children(parent).find(\n (child) => child.localName === localName\n );\n if (existing) {\n return existing;\n }\n const created = parent.ownerDocument.createElementNS(W_NS, `w:${localName}`);\n return position === 'first'\n ? parent.insertBefore(created, parent.firstChild)\n : parent.appendChild(created);\n}\n\nfunction requireElement(dom: Document, localName: string): Element {\n const element = dom.getElementsByTagNameNS(W_NS, localName)[0];\n if (!element) {\n throw new Error(\n `Cannot apply font preset: styles.xml has no <w:${localName}> element`\n );\n }\n return element;\n}\n"]}
|
package/build/font-presets.d.ts
CHANGED
|
@@ -34,6 +34,33 @@ export interface ParagraphStyle {
|
|
|
34
34
|
/** First-line indent, in characters of the body font size. */
|
|
35
35
|
firstLineIndentChars?: number;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* How table cells are laid out. Cells sit outside the page grid: exact grid
|
|
39
|
+
* spacing would stretch every row and clip content that wraps.
|
|
40
|
+
*/
|
|
41
|
+
export interface TableStyle {
|
|
42
|
+
/** Word's 表格属性 → 单元格 → 垂直对齐方式. */
|
|
43
|
+
verticalAlign: 'top' | 'center' | 'bottom';
|
|
44
|
+
/** Line spacing of the paragraphs inside the cells. */
|
|
45
|
+
lineSpacing: LineSpacing;
|
|
46
|
+
/** Word's 如果定义了文档网格,则与网格对齐 (`w:snapToGrid`). */
|
|
47
|
+
snapToGrid: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** How lists are laid out beyond the paragraph rules they share with the body. */
|
|
50
|
+
export interface ListStyle {
|
|
51
|
+
/**
|
|
52
|
+
* Bullet glyph per nesting level, the way Word's multi-level bullet library
|
|
53
|
+
* goes ● then ○ then ▪. Levels deeper than the list repeat its last glyph.
|
|
54
|
+
*/
|
|
55
|
+
bullets: string[];
|
|
56
|
+
/**
|
|
57
|
+
* Number nested ordered levels across the parent's number, so they read
|
|
58
|
+
* 1.1 and 1.1.1 the way Word's multi-level list does. This also makes every
|
|
59
|
+
* level of a list share one numbering definition, which is how Word counts
|
|
60
|
+
* them; without it the generator's per-level counters restart at 1.
|
|
61
|
+
*/
|
|
62
|
+
multilevelNumbers: boolean;
|
|
63
|
+
}
|
|
37
64
|
/** Paper and text block, in millimeters. */
|
|
38
65
|
export interface PageLayout {
|
|
39
66
|
widthMm: number;
|
|
@@ -61,6 +88,10 @@ export interface FontPreset {
|
|
|
61
88
|
* `pageMargins` take precedence.
|
|
62
89
|
*/
|
|
63
90
|
page?: PageLayout;
|
|
91
|
+
/** Layout for table cells, which sit outside the page grid. */
|
|
92
|
+
table?: TableStyle;
|
|
93
|
+
/** List layout, written into the numbering definitions. */
|
|
94
|
+
list?: ListStyle;
|
|
64
95
|
}
|
|
65
96
|
/**
|
|
66
97
|
* Chinese official documents (公文), after GB/T 9704-2012 《党政机关公文格式》:
|
|
@@ -83,6 +114,12 @@ export interface FontPreset {
|
|
|
83
114
|
* practice.
|
|
84
115
|
*/
|
|
85
116
|
export declare const CHINESE_OFFICIAL_DOC_FONTS: FontPreset;
|
|
117
|
+
/**
|
|
118
|
+
* The 公文 preset with multi-level numbering: nested items read 1.1 and 1.1.1,
|
|
119
|
+
* which is how contracts and similar instruments number their clauses rather
|
|
120
|
+
* than how a 公文 does.
|
|
121
|
+
*/
|
|
122
|
+
export declare const CHINESE_OFFICIAL_MULTILEVEL_FONTS: FontPreset;
|
|
86
123
|
export declare function mmToTwips(mm: number): number;
|
|
87
124
|
/** The presets offered in the UI, keyed by the value of their `<option>`. */
|
|
88
125
|
export declare const FONT_PRESETS: Record<string, FontPreset>;
|
package/build/font-presets.js
CHANGED
|
@@ -4,6 +4,11 @@ const BODY_FONT = '仿宋';
|
|
|
4
4
|
const SIZE_ER = 22;
|
|
5
5
|
/** Chinese size 3 (三号). */
|
|
6
6
|
const SIZE_SAN = 16;
|
|
7
|
+
/**
|
|
8
|
+
* Bullets per nesting level, as in Word's multi-level bullet library. The
|
|
9
|
+
* generator gives every level the same Symbol glyph, so nesting is invisible.
|
|
10
|
+
*/
|
|
11
|
+
const BULLET_GLYPHS = ['●', '○', '▪'];
|
|
7
12
|
/**
|
|
8
13
|
* Chinese official documents (公文), after GB/T 9704-2012 《党政机关公文格式》:
|
|
9
14
|
*
|
|
@@ -58,6 +63,19 @@ export const CHINESE_OFFICIAL_DOC_FONTS = {
|
|
|
58
63
|
marginsMm: { top: 37, right: 26, bottom: 35, left: 28 },
|
|
59
64
|
grid: { linesPerPage: 22, charsPerLine: 28 },
|
|
60
65
|
},
|
|
66
|
+
table: { verticalAlign: 'center', lineSpacing: 'single', snapToGrid: false },
|
|
67
|
+
// GB/T 9704-2012 §7.3.3 numbers its levels 一、 (一) 1. (1), not 1.1, so a
|
|
68
|
+
// 公文 does not count across parents. See CHINESE_OFFICIAL_MULTILEVEL_FONTS.
|
|
69
|
+
list: { bullets: BULLET_GLYPHS, multilevelNumbers: false },
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The 公文 preset with multi-level numbering: nested items read 1.1 and 1.1.1,
|
|
73
|
+
* which is how contracts and similar instruments number their clauses rather
|
|
74
|
+
* than how a 公文 does.
|
|
75
|
+
*/
|
|
76
|
+
export const CHINESE_OFFICIAL_MULTILEVEL_FONTS = {
|
|
77
|
+
...CHINESE_OFFICIAL_DOC_FONTS,
|
|
78
|
+
list: { bullets: BULLET_GLYPHS, multilevelNumbers: true },
|
|
61
79
|
};
|
|
62
80
|
/** Twips (1/20 point) per millimeter. */
|
|
63
81
|
const TWIPS_PER_MM = 1440 / 25.4;
|
|
@@ -67,6 +85,7 @@ export function mmToTwips(mm) {
|
|
|
67
85
|
/** The presets offered in the UI, keyed by the value of their `<option>`. */
|
|
68
86
|
export const FONT_PRESETS = {
|
|
69
87
|
'chinese-official': CHINESE_OFFICIAL_DOC_FONTS,
|
|
88
|
+
'chinese-official-multilevel': CHINESE_OFFICIAL_MULTILEVEL_FONTS,
|
|
70
89
|
};
|
|
71
90
|
/**
|
|
72
91
|
* Whether most of the letters in `text` are Chinese characters, used to suggest
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font-presets.js","sourceRoot":"","sources":["../src/font-presets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"font-presets.js","sourceRoot":"","sources":["../src/font-presets.ts"],"names":[],"mappings":"AA8FA,MAAM,UAAU,GAAG,iBAAiB,CAAC;AACrC,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,2BAA2B;AAC3B,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,2BAA2B;AAC3B,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAe;IACpD,IAAI,EAAE;QACJ,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,KAAK;YACX,QAAQ,EAAE,IAAI;SACf;QAC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GAAG,0BAA0B;IAC7B,IAAI,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,IAAI,EAAE;CAC1D,CAAC;AAEF,yCAAyC;AACzC,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,CAAC;AAEjC,MAAM,UAAU,SAAS,CAAC,EAAU;IAClC,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;AACvC,CAAC;AAED,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAA+B;IACtD,kBAAkB,EAAE,0BAA0B;IAC9C,6BAA6B,EAAE,iCAAiC;CACjE,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IACxD,MAAM,IAAI,GACR,IAAI,CAAC,KAAK,CAAC,4CAA4C,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IAExE,OAAO,GAAG,IAAI,EAAE,IAAI,GAAG,GAAG,OAAO,IAAI,GAAG,IAAI,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * Typography for one level of a document.\n *\n * Word selects a typeface per character class: Latin letters and digits are\n * rendered from the `w:ascii`/`w:hAnsi` run-property slots, Chinese characters\n * from `w:eastAsia`. Naming both fonts per level is therefore enough to keep\n * Chinese text in a Chinese face and Latin text in a Latin one.\n */\nexport interface LevelStyle {\n /** Typeface for Latin letters, digits and punctuation. */\n latin: string;\n /** Typeface for Chinese characters. */\n eastAsia: string;\n /** Font size in points. Chinese named sizes: size 2 (二号) = 22pt, size 3 (三号) = 16pt. */\n sizePt: number;\n bold: boolean;\n /** Centers the paragraph, without the first-line indent. */\n centered?: boolean;\n}\n\n/**\n * Word line spacing rule:\n *\n * - `single`: single line spacing.\n * - `grid`: exact line spacing at the line pitch of the page's document grid,\n * with widow control off, so every full page holds `page.grid.linesPerPage`\n * lines. Needs `page.grid`.\n */\nexport type LineSpacing = 'single' | 'grid';\n\nexport interface ParagraphStyle {\n /** Paragraph spacing before and after, in points. */\n beforePt: number;\n afterPt: number;\n lineSpacing: LineSpacing;\n /** First-line indent, in characters of the body font size. */\n firstLineIndentChars?: number;\n}\n\n/**\n * How table cells are laid out. Cells sit outside the page grid: exact grid\n * spacing would stretch every row and clip content that wraps.\n */\nexport interface TableStyle {\n /** Word's 表格属性 → 单元格 → 垂直对齐方式. */\n verticalAlign: 'top' | 'center' | 'bottom';\n /** Line spacing of the paragraphs inside the cells. */\n lineSpacing: LineSpacing;\n /** Word's 如果定义了文档网格,则与网格对齐 (`w:snapToGrid`). */\n snapToGrid: boolean;\n}\n\n/** How lists are laid out beyond the paragraph rules they share with the body. */\nexport interface ListStyle {\n /**\n * Bullet glyph per nesting level, the way Word's multi-level bullet library\n * goes ● then ○ then ▪. Levels deeper than the list repeat its last glyph.\n */\n bullets: string[];\n /**\n * Number nested ordered levels across the parent's number, so they read\n * 1.1 and 1.1.1 the way Word's multi-level list does. This also makes every\n * level of a list share one numbering definition, which is how Word counts\n * them; without it the generator's per-level counters restart at 1.\n */\n multilevelNumbers: boolean;\n}\n\n/** Paper and text block, in millimeters. */\nexport interface PageLayout {\n widthMm: number;\n heightMm: number;\n marginsMm: { top: number; right: number; bottom: number; left: number };\n /** Word's document grid (文档网格): a fixed number of lines and characters. */\n grid?: { linesPerPage: number; charsPerLine: number };\n}\n\nexport interface FontPreset {\n body: LevelStyle;\n /** Six entries, applied to the `Heading1` - `Heading6` styles. */\n headings: LevelStyle[];\n /** Shared by the body text and every heading level. */\n paragraph: ParagraphStyle;\n /**\n * Page size and margins. Margins passed to `convertMarkdownToWord` as\n * `pageMargins` take precedence.\n */\n page?: PageLayout;\n /** Layout for table cells, which sit outside the page grid. */\n table?: TableStyle;\n /** List layout, written into the numbering definitions. */\n list?: ListStyle;\n}\n\nconst LATIN_FONT = 'Times New Roman';\nconst BODY_FONT = '仿宋';\n\n/** Chinese size 2 (二号). */\nconst SIZE_ER = 22;\n/** Chinese size 3 (三号). */\nconst SIZE_SAN = 16;\n\n/**\n * Bullets per nesting level, as in Word's multi-level bullet library. The\n * generator gives every level the same Symbol glyph, so nesting is invisible.\n */\nconst BULLET_GLYPHS = ['●', '○', '▪'];\n\n/**\n * Chinese official documents (公文), after GB/T 9704-2012 《党政机关公文格式》:\n *\n * - Body: FangSong (仿宋), size 3\n * - Heading 1 (the title): FZXiaoBiaoSong (方正小标宋简体), size 2, centered (7.3.1)\n * - Heading 2: SimHei (黑体), size 3\n * - Heading 3: KaiTi (楷体), size 3\n * - Heading 4: FangSong, size 3, bold. The standard sets levels 3 and 4 in\n * plain 仿宋, but a bolded fourth level is how these documents are made.\n * - Heading 5 and below: FangSong, size 3, not bold.\n * - A4 paper with a 37mm top and 28mm left margin around a 156 × 225mm text\n * block (5.1, 5.2.1)\n * - 22 lines of 28 characters per page (5.2.3), as a document grid with exact\n * line spacing at its pitch\n * - Paragraphs indented two characters (7.3.3), headings below the title too\n *\n * Every level uses Times New Roman for Latin text and no space before or after\n * paragraphs. The standard names no Latin font; Times New Roman is common\n * practice.\n */\nexport const CHINESE_OFFICIAL_DOC_FONTS: FontPreset = {\n body: {\n latin: LATIN_FONT,\n eastAsia: BODY_FONT,\n sizePt: SIZE_SAN,\n bold: false,\n },\n headings: [\n {\n latin: LATIN_FONT,\n eastAsia: '方正小标宋简体',\n sizePt: SIZE_ER,\n bold: false,\n centered: true,\n },\n { latin: LATIN_FONT, eastAsia: '黑体', sizePt: SIZE_SAN, bold: false },\n { latin: LATIN_FONT, eastAsia: '楷体', sizePt: SIZE_SAN, bold: false },\n { latin: LATIN_FONT, eastAsia: BODY_FONT, sizePt: SIZE_SAN, bold: true },\n { latin: LATIN_FONT, eastAsia: BODY_FONT, sizePt: SIZE_SAN, bold: false },\n { latin: LATIN_FONT, eastAsia: BODY_FONT, sizePt: SIZE_SAN, bold: false },\n ],\n paragraph: {\n beforePt: 0,\n afterPt: 0,\n lineSpacing: 'grid',\n firstLineIndentChars: 2,\n },\n page: {\n widthMm: 210,\n heightMm: 297,\n // 297 - 37 - 225 = 35 at the bottom, 210 - 28 - 156 = 26 on the right.\n marginsMm: { top: 37, right: 26, bottom: 35, left: 28 },\n grid: { linesPerPage: 22, charsPerLine: 28 },\n },\n table: { verticalAlign: 'center', lineSpacing: 'single', snapToGrid: false },\n // GB/T 9704-2012 §7.3.3 numbers its levels 一、 (一) 1. (1), not 1.1, so a\n // 公文 does not count across parents. See CHINESE_OFFICIAL_MULTILEVEL_FONTS.\n list: { bullets: BULLET_GLYPHS, multilevelNumbers: false },\n};\n\n/**\n * The 公文 preset with multi-level numbering: nested items read 1.1 and 1.1.1,\n * which is how contracts and similar instruments number their clauses rather\n * than how a 公文 does.\n */\nexport const CHINESE_OFFICIAL_MULTILEVEL_FONTS: FontPreset = {\n ...CHINESE_OFFICIAL_DOC_FONTS,\n list: { bullets: BULLET_GLYPHS, multilevelNumbers: true },\n};\n\n/** Twips (1/20 point) per millimeter. */\nconst TWIPS_PER_MM = 1440 / 25.4;\n\nexport function mmToTwips(mm: number): number {\n return Math.round(mm * TWIPS_PER_MM);\n}\n\n/** The presets offered in the UI, keyed by the value of their `<option>`. */\nexport const FONT_PRESETS: Record<string, FontPreset> = {\n 'chinese-official': CHINESE_OFFICIAL_DOC_FONTS,\n 'chinese-official-multilevel': CHINESE_OFFICIAL_MULTILEVEL_FONTS,\n};\n\n/**\n * Whether most of the letters in `text` are Chinese characters, used to suggest\n * the Chinese preset. Kana means Japanese, which also uses Han characters, so\n * text with a meaningful share of kana does not count.\n */\nexport function isMostlyChinese(text: string): boolean {\n const letters = text.match(/\\p{L}/gu)?.length ?? 0;\n const han = text.match(/\\p{Script=Han}/gu)?.length ?? 0;\n const kana =\n text.match(/[\\p{Script=Hiragana}\\p{Script=Katakana}]/gu)?.length ?? 0;\n\n return han >= 10 && han / letters >= 0.5 && kana < han / 10;\n}\n"]}
|
package/build/main.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { convertMarkdownToWord, type ConversionOptions } from './converter.js';
|
|
2
2
|
export { extractTitle, parseMarkdownToHtml } from './markdown-parser.js';
|
|
3
|
-
export { CHINESE_OFFICIAL_DOC_FONTS, FONT_PRESETS, type FontPreset, type LevelStyle, type LineSpacing, type PageLayout, type ParagraphStyle, } from './font-presets.js';
|
|
3
|
+
export { CHINESE_OFFICIAL_DOC_FONTS, CHINESE_OFFICIAL_MULTILEVEL_FONTS, FONT_PRESETS, type FontPreset, type LevelStyle, type LineSpacing, type ListStyle, type PageLayout, type ParagraphStyle, type TableStyle, } from './font-presets.js';
|
package/build/main.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
// the DOM APIs the converter needs first.
|
|
4
4
|
export { convertMarkdownToWord } from './converter.js';
|
|
5
5
|
export { extractTitle, parseMarkdownToHtml } from './markdown-parser.js';
|
|
6
|
-
export { CHINESE_OFFICIAL_DOC_FONTS, FONT_PRESETS, } from './font-presets.js';
|
|
6
|
+
export { CHINESE_OFFICIAL_DOC_FONTS, CHINESE_OFFICIAL_MULTILEVEL_FONTS, FONT_PRESETS, } from './font-presets.js';
|
|
7
7
|
//# sourceMappingURL=main.js.map
|
package/build/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,0CAA0C;AAC1C,OAAO,EAAE,qBAAqB,EAA0B,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EACL,0BAA0B,EAC1B,YAAY,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,0CAA0C;AAC1C,OAAO,EAAE,qBAAqB,EAA0B,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EACL,0BAA0B,EAC1B,iCAAiC,EACjC,YAAY,GAQb,MAAM,mBAAmB,CAAC","sourcesContent":["// The npm package's entry: the converter without the browser UI (index.ts).\n// Browsers and bundlers load this directly; Node loads node.ts, which supplies\n// the DOM APIs the converter needs first.\nexport { convertMarkdownToWord, type ConversionOptions } from './converter.js';\nexport { extractTitle, parseMarkdownToHtml } from './markdown-parser.js';\nexport {\n CHINESE_OFFICIAL_DOC_FONTS,\n CHINESE_OFFICIAL_MULTILEVEL_FONTS,\n FONT_PRESETS,\n type FontPreset,\n type LevelStyle,\n type LineSpacing,\n type ListStyle,\n type PageLayout,\n type ParagraphStyle,\n type TableStyle,\n} from './font-presets.js';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-to-word",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"mcpName": "io.github.benbalter/markdown-to-word",
|
|
5
5
|
"description": "Convert GitHub Flavored Markdown to Word (.docx) documents in Node or the browser",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"!build/mcp.d.ts"
|
|
27
27
|
],
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": "
|
|
29
|
+
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"dev": "astro dev",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@astrojs/check": "^0.9.11",
|
|
53
53
|
"@astrojs/sitemap": "^3.7.4",
|
|
54
54
|
"@eslint/js": "^10.0.1",
|
|
55
|
-
"@nuasite/checks": "^0.
|
|
55
|
+
"@nuasite/checks": "^0.67.0",
|
|
56
56
|
"@playwright/test": "^1.64.1",
|
|
57
57
|
"@tailwindcss/typography": "^0.5.20",
|
|
58
58
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"buffer": "^6.0.3",
|
|
78
78
|
"commander": "^15.0.0",
|
|
79
79
|
"dompurify": "^3.4.17",
|
|
80
|
-
"jsdom": "^
|
|
80
|
+
"jsdom": "^31.0.0",
|
|
81
81
|
"jszip": "^3.10.2",
|
|
82
82
|
"marked": "^18.1.1",
|
|
83
83
|
"marked-footnote": "^1.4.0",
|