@folijs/docx 0.5.0 → 1.0.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/CHANGELOG.md +157 -0
- package/README.md +54 -17
- package/dist/custom.d.ts +2 -0
- package/dist/custom.d.ts.map +1 -0
- package/dist/custom.js +216 -0
- package/dist/custom.js.map +1 -0
- package/dist/export/balance.d.ts +2 -0
- package/dist/export/balance.d.ts.map +1 -0
- package/dist/export/balance.js +112 -0
- package/dist/export/balance.js.map +1 -0
- package/dist/export/content.d.ts +1 -14
- package/dist/export/content.d.ts.map +1 -1
- package/dist/export/content.js +157 -22
- package/dist/export/content.js.map +1 -1
- package/dist/export/controls.d.ts +2 -0
- package/dist/export/controls.d.ts.map +1 -0
- package/dist/export/controls.js +233 -0
- package/dist/export/controls.js.map +1 -0
- package/dist/export/index.d.ts +8 -2
- package/dist/export/index.d.ts.map +1 -1
- package/dist/export/index.js +218 -18
- package/dist/export/index.js.map +1 -1
- package/dist/export/parts.d.ts +1 -16
- package/dist/export/parts.d.ts.map +1 -1
- package/dist/export/parts.js +79 -11
- package/dist/export/parts.js.map +1 -1
- package/dist/export/pictures.d.ts +0 -42
- package/dist/export/pictures.d.ts.map +1 -1
- package/dist/export/pictures.js +24 -4
- package/dist/export/pictures.js.map +1 -1
- package/dist/export/properties.d.ts +1 -41
- package/dist/export/properties.d.ts.map +1 -1
- package/dist/export/properties.js +74 -15
- package/dist/export/properties.js.map +1 -1
- package/dist/export/tables.d.ts +0 -19
- package/dist/export/tables.d.ts.map +1 -1
- package/dist/export/tables.js +15 -3
- package/dist/export/tables.js.map +1 -1
- package/dist/export/xmlout.d.ts +1 -61
- package/dist/export/xmlout.d.ts.map +1 -1
- package/dist/export/xmlout.js +34 -7
- package/dist/export/xmlout.js.map +1 -1
- package/dist/import/content.d.ts +1 -33
- package/dist/import/content.d.ts.map +1 -1
- package/dist/import/content.js +208 -17
- package/dist/import/content.js.map +1 -1
- package/dist/import/controls.d.ts +2 -0
- package/dist/import/controls.d.ts.map +1 -0
- package/dist/import/controls.js +121 -0
- package/dist/import/controls.js.map +1 -0
- package/dist/import/index.d.ts +1 -1
- package/dist/import/index.d.ts.map +1 -1
- package/dist/import/index.js +82 -14
- package/dist/import/index.js.map +1 -1
- package/dist/import/ooxml.d.ts +1 -37
- package/dist/import/ooxml.d.ts.map +1 -1
- package/dist/import/ooxml.js +44 -8
- package/dist/import/ooxml.js.map +1 -1
- package/dist/import/parts.d.ts +1 -33
- package/dist/import/parts.d.ts.map +1 -1
- package/dist/import/parts.js +36 -10
- package/dist/import/parts.js.map +1 -1
- package/dist/import/pictures.d.ts +1 -33
- package/dist/import/pictures.d.ts.map +1 -1
- package/dist/import/pictures.js +7 -1
- package/dist/import/pictures.js.map +1 -1
- package/dist/import/properties.d.ts +1 -43
- package/dist/import/properties.d.ts.map +1 -1
- package/dist/import/properties.js +84 -6
- package/dist/import/properties.js.map +1 -1
- package/dist/import/report.d.ts +0 -10
- package/dist/import/report.d.ts.map +1 -1
- package/dist/import/report.js +1 -0
- package/dist/import/report.js.map +1 -1
- package/dist/import/stories.d.ts +2 -0
- package/dist/import/stories.d.ts.map +1 -0
- package/dist/import/stories.js +131 -0
- package/dist/import/stories.js.map +1 -0
- package/dist/import/tables.d.ts +0 -24
- package/dist/import/tables.d.ts.map +1 -1
- package/dist/import/tables.js +25 -6
- package/dist/import/tables.js.map +1 -1
- package/dist/package.d.ts +8 -4
- package/dist/package.d.ts.map +1 -1
- package/dist/package.js +38 -4
- package/dist/package.js.map +1 -1
- package/dist/settings.d.ts +1 -7
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +186 -26
- package/dist/settings.js.map +1 -1
- package/dist/xml.d.ts +8 -0
- package/dist/xml.d.ts.map +1 -1
- package/dist/xml.js +30 -2
- package/dist/xml.js.map +1 -1
- package/dist/zip.d.ts +0 -47
- package/dist/zip.d.ts.map +1 -1
- package/dist/zip.js +11 -2
- package/dist/zip.js.map +1 -1
- package/package.json +6 -5
- package/src/custom.ts +254 -0
- package/src/export/balance.ts +114 -0
- package/src/export/content.ts +203 -19
- package/src/export/controls.ts +260 -0
- package/src/export/index.ts +268 -20
- package/src/export/parts.ts +102 -10
- package/src/export/pictures.ts +21 -5
- package/src/export/properties.ts +90 -18
- package/src/export/tables.ts +15 -3
- package/src/export/xmlout.ts +36 -7
- package/src/import/content.ts +219 -17
- package/src/import/controls.ts +141 -0
- package/src/import/index.ts +103 -22
- package/src/import/ooxml.ts +44 -8
- package/src/import/parts.ts +44 -19
- package/src/import/pictures.ts +8 -1
- package/src/import/properties.ts +90 -6
- package/src/import/report.ts +1 -0
- package/src/import/stories.ts +134 -0
- package/src/import/tables.ts +25 -6
- package/src/package.ts +56 -6
- package/src/settings.ts +204 -27
- package/src/xml.ts +42 -2
- package/src/zip.ts +17 -5
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { controlProperties } from "../import/controls.js";
|
|
2
|
+
import { child, elements, W14, W15 } from "../import/ooxml.js";
|
|
3
|
+
import { Recorder } from "../import/report.js";
|
|
4
|
+
import { DocxError } from "../package.js";
|
|
5
|
+
import { same } from "./properties.js";
|
|
6
|
+
import { el, escapeAttribute, fragment, val } from "./xmlout.js";
|
|
7
|
+
/** `w:sdtPr`'s children in the order the schema gives them; the kind's element comes after. */
|
|
8
|
+
const ORDER = [
|
|
9
|
+
"rPr",
|
|
10
|
+
"alias",
|
|
11
|
+
"tag",
|
|
12
|
+
"id",
|
|
13
|
+
"lock",
|
|
14
|
+
"placeholder",
|
|
15
|
+
"temporary",
|
|
16
|
+
"showingPlcHdr",
|
|
17
|
+
"dataBinding",
|
|
18
|
+
"label",
|
|
19
|
+
"tabIndex",
|
|
20
|
+
];
|
|
21
|
+
const ID = /(<[\w.-]+:id\b[^>]*?[\w.-]+:val=")(-?\d+)(")/;
|
|
22
|
+
const itemsXml = (items) => items
|
|
23
|
+
.map((item) => el("w:listItem", {
|
|
24
|
+
"w:displayText": item.display ?? item.value,
|
|
25
|
+
"w:value": item.value,
|
|
26
|
+
}))
|
|
27
|
+
.join("");
|
|
28
|
+
/** An extension's element, its namespace declared on it where the part does not. */
|
|
29
|
+
const extension = (prefix, uri, ns) => ns.prefixes.has(prefix) ? {} : { [`xmlns:${prefix}`]: uri };
|
|
30
|
+
/** The element of a control's kind, as Word writes it. */
|
|
31
|
+
function kindXml(control, ns) {
|
|
32
|
+
switch (control.kind) {
|
|
33
|
+
case "text":
|
|
34
|
+
return el("w:text", control.multiLine ? { "w:multiLine": "1" } : {});
|
|
35
|
+
case "dropDown":
|
|
36
|
+
return el("w:dropDownList", {}, itemsXml(control.items ?? []));
|
|
37
|
+
case "comboBox":
|
|
38
|
+
return el("w:comboBox", {}, itemsXml(control.items ?? []));
|
|
39
|
+
case "date":
|
|
40
|
+
return el("w:date", { "w:fullDate": control.date }, val("dateFormat", control.dateFormat ?? "d MMMM yyyy") +
|
|
41
|
+
val("lid", "en-US") +
|
|
42
|
+
val("storeMappedDataAs", "dateTime") +
|
|
43
|
+
val("calendar", "gregorian"));
|
|
44
|
+
case "checkbox": {
|
|
45
|
+
const glyph = (name, state, code) => el(`w14:${name}`, {
|
|
46
|
+
"w14:val": state?.value ?? code,
|
|
47
|
+
"w14:font": state?.font ?? "MS Gothic",
|
|
48
|
+
});
|
|
49
|
+
return el("w14:checkbox", extension("w14", W14, ns), el("w14:checked", { "w14:val": control.checked ? "1" : "0" }) +
|
|
50
|
+
glyph("checkedState", control.checkedState, "2612") +
|
|
51
|
+
glyph("uncheckedState", control.uncheckedState, "2610"));
|
|
52
|
+
}
|
|
53
|
+
case "picture":
|
|
54
|
+
return el("w:picture");
|
|
55
|
+
case "repeating":
|
|
56
|
+
return el("w15:repeatingSection", extension("w15", W15, ns));
|
|
57
|
+
case "repeatingItem":
|
|
58
|
+
return el("w15:repeatingSectionItem", extension("w15", W15, ns));
|
|
59
|
+
default:
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** The whole `w:sdtPr` of a control that has none yet. */
|
|
64
|
+
function newProperties(control, id, ns) {
|
|
65
|
+
const { placeholder } = control;
|
|
66
|
+
return el("w:sdtPr", {}, val("alias", control.alias) +
|
|
67
|
+
val("tag", control.tag) +
|
|
68
|
+
val("id", id) +
|
|
69
|
+
val("lock", control.lock) +
|
|
70
|
+
(placeholder?.docPart ? el("w:placeholder", {}, val("docPart", placeholder.docPart)) : "") +
|
|
71
|
+
(placeholder?.showing ? el("w:showingPlcHdr") : "") +
|
|
72
|
+
kindXml(control, ns));
|
|
73
|
+
}
|
|
74
|
+
/** The kept `w:sdtPr` with what `control` says differently written into it. */
|
|
75
|
+
function patched(source, pr, control, kept) {
|
|
76
|
+
const edits = [];
|
|
77
|
+
const children = elements(pr);
|
|
78
|
+
const prefix = pr.name.includes(":") ? `${pr.name.split(":")[0]}:` : "";
|
|
79
|
+
const named = (local) => children.find((c) => c.ns === pr.ns && c.local === local);
|
|
80
|
+
/** Where a new child goes: before the first that comes after it. */
|
|
81
|
+
const insertAt = (local) => {
|
|
82
|
+
const rank = ORDER.indexOf(local);
|
|
83
|
+
const next = children.find((c) => {
|
|
84
|
+
const at = c.ns === pr.ns ? ORDER.indexOf(c.local) : -1;
|
|
85
|
+
return at < 0 || at > rank;
|
|
86
|
+
});
|
|
87
|
+
return next ? next.start : pr.closeStart;
|
|
88
|
+
};
|
|
89
|
+
const child1 = (local, value) => {
|
|
90
|
+
const old = named(local);
|
|
91
|
+
const xml = value === undefined ? "" : el(`${prefix}${local}`, { [`${prefix}val`]: value });
|
|
92
|
+
if (old)
|
|
93
|
+
edits.push({ from: old.start, to: old.end, text: xml });
|
|
94
|
+
else if (xml) {
|
|
95
|
+
const at = insertAt(local);
|
|
96
|
+
edits.push({ from: at, to: at, text: xml });
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const isEmptyTag = (element) => element.openEnd === element.end;
|
|
100
|
+
/** `element`'s start tag with attribute `name` set, or gone. */
|
|
101
|
+
const withAttribute = (element, name, value) => {
|
|
102
|
+
const end = isEmptyTag(element) ? element.openEnd - 2 : element.openEnd - 1;
|
|
103
|
+
let tag = source.slice(element.start, end);
|
|
104
|
+
tag = tag.replace(new RegExp(`\\s${name}\\s*=\\s*("[^"]*"|'[^']*')`), "");
|
|
105
|
+
if (value !== undefined)
|
|
106
|
+
tag += ` ${name}="${escapeAttribute(value)}"`;
|
|
107
|
+
edits.push({ from: element.start, to: end, text: tag });
|
|
108
|
+
};
|
|
109
|
+
/** `element` holding `inner` in place of its children (none: `inner` goes first among them). */
|
|
110
|
+
const withChildren = (element, inner, replace = true) => {
|
|
111
|
+
if (isEmptyTag(element))
|
|
112
|
+
edits.push({
|
|
113
|
+
from: element.openEnd - 2,
|
|
114
|
+
to: element.end,
|
|
115
|
+
text: `>${inner}</${element.name}>`,
|
|
116
|
+
});
|
|
117
|
+
else
|
|
118
|
+
edits.push({
|
|
119
|
+
from: element.openEnd,
|
|
120
|
+
to: replace ? element.closeStart : element.openEnd,
|
|
121
|
+
text: inner,
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
if (control.kind !== kept.kind)
|
|
125
|
+
throw new DocxError("A content control cannot change kind");
|
|
126
|
+
if (control.alias !== kept.alias)
|
|
127
|
+
child1("alias", control.alias);
|
|
128
|
+
if (control.tag !== kept.tag)
|
|
129
|
+
child1("tag", control.tag);
|
|
130
|
+
if (control.lock !== kept.lock)
|
|
131
|
+
child1("lock", control.lock);
|
|
132
|
+
const showing = control.placeholder?.showing === true;
|
|
133
|
+
if (showing !== (kept.placeholder?.showing === true)) {
|
|
134
|
+
const old = named("showingPlcHdr");
|
|
135
|
+
if (old)
|
|
136
|
+
edits.push({ from: old.start, to: old.end, text: showing ? `<${old.name}/>` : "" });
|
|
137
|
+
else {
|
|
138
|
+
const at = insertAt("showingPlcHdr");
|
|
139
|
+
edits.push({ from: at, to: at, text: `<${prefix}showingPlcHdr/>` });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const list = named("dropDownList") ?? named("comboBox");
|
|
143
|
+
if (list && !same(control.items, kept.items))
|
|
144
|
+
withChildren(list, itemsXml(control.items ?? []));
|
|
145
|
+
const date = named("date");
|
|
146
|
+
if (date) {
|
|
147
|
+
if (control.date !== kept.date)
|
|
148
|
+
withAttribute(date, `${prefix}fullDate`, control.date);
|
|
149
|
+
if (control.dateFormat !== kept.dateFormat) {
|
|
150
|
+
const format = child(date, "dateFormat");
|
|
151
|
+
const xml = el(`${prefix}dateFormat`, { [`${prefix}val`]: control.dateFormat });
|
|
152
|
+
if (format)
|
|
153
|
+
edits.push({ from: format.start, to: format.end, text: xml });
|
|
154
|
+
else
|
|
155
|
+
withChildren(date, xml, false);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const text = named("text");
|
|
159
|
+
if (text && (control.multiLine ?? false) !== (kept.multiLine ?? false))
|
|
160
|
+
withAttribute(text, `${prefix}multiLine`, control.multiLine ? "1" : undefined);
|
|
161
|
+
const box = children.find((c) => c.ns === W14 && c.local === "checkbox");
|
|
162
|
+
if (box && (control.checked ?? false) !== (kept.checked ?? false)) {
|
|
163
|
+
const checked = elements(box).find((c) => c.ns === W14 && c.local === "checked");
|
|
164
|
+
const name = checked?.name ?? box.name.replace("checkbox", "checked");
|
|
165
|
+
const boxPrefix = name.slice(0, name.indexOf(":") + 1);
|
|
166
|
+
const xml = el(name, { [`${boxPrefix}val`]: control.checked ? "1" : "0" });
|
|
167
|
+
if (checked)
|
|
168
|
+
edits.push({ from: checked.start, to: checked.end, text: xml });
|
|
169
|
+
else
|
|
170
|
+
withChildren(box, xml, false);
|
|
171
|
+
}
|
|
172
|
+
let out = source.slice(pr.start, pr.end);
|
|
173
|
+
// From the end; of two put at one place, the first made ends up first.
|
|
174
|
+
const order = edits.map((edit, i) => ({ edit, i }));
|
|
175
|
+
order.sort((a, b) => b.edit.from - a.edit.from || b.edit.to - a.edit.to || b.i - a.i);
|
|
176
|
+
for (const { edit } of order)
|
|
177
|
+
out = out.slice(0, edit.from - pr.start) + edit.text + out.slice(edit.to - pr.start);
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
/** @internal */
|
|
181
|
+
export class ControlWriter {
|
|
182
|
+
controls;
|
|
183
|
+
#written = new Set();
|
|
184
|
+
/** Every `w:id` the document's controls hold. */
|
|
185
|
+
#held = new Set();
|
|
186
|
+
/** Above any id Word gives. */
|
|
187
|
+
#nextId = 2_000_000_000;
|
|
188
|
+
constructor(controls) {
|
|
189
|
+
this.controls = controls;
|
|
190
|
+
for (const control of Object.values(controls)) {
|
|
191
|
+
const id = control.ext && ID.exec(control.ext)?.[2];
|
|
192
|
+
if (id)
|
|
193
|
+
this.#held.add(id);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
#freshId() {
|
|
197
|
+
while (this.#held.has(String(this.#nextId)))
|
|
198
|
+
this.#nextId++;
|
|
199
|
+
return this.#nextId++;
|
|
200
|
+
}
|
|
201
|
+
/** What goes before a control's content, in the order `w:sdt` requires. */
|
|
202
|
+
parts(id, ns) {
|
|
203
|
+
if (!Object.hasOwn(this.controls, id))
|
|
204
|
+
throw new DocxError(`Content control ${id.slice(0, 64)} has no properties`);
|
|
205
|
+
const control = this.controls[id];
|
|
206
|
+
let properties = control.ext
|
|
207
|
+
? this.#kept(control, ns)
|
|
208
|
+
: newProperties(control, this.#freshId(), ns);
|
|
209
|
+
// The same control written twice: an edit has separated its parts, and ids are unique.
|
|
210
|
+
if (this.#written.has(id))
|
|
211
|
+
properties = properties.replace(ID, (_, start, _id, end) => `${start}${this.#freshId()}${end}`);
|
|
212
|
+
this.#written.add(id);
|
|
213
|
+
return { properties };
|
|
214
|
+
}
|
|
215
|
+
#kept(control, ns) {
|
|
216
|
+
const { element, source } = fragment(control.ext, ns, "sdt");
|
|
217
|
+
const pr = child(element, "sdtPr");
|
|
218
|
+
const reread = controlProperties(element, { source, report: new Recorder() });
|
|
219
|
+
const end = child(element, "sdtEndPr");
|
|
220
|
+
const after = end ? source.slice(end.start, end.end) : "";
|
|
221
|
+
const whatItSays = (c) => {
|
|
222
|
+
const { ext: _ext, deleted: _deleted, placeholder, ...rest } = c ?? {};
|
|
223
|
+
const { text: _text, ...shown } = placeholder ?? {};
|
|
224
|
+
return { ...rest, placeholder: { ...shown, showing: shown.showing === true } };
|
|
225
|
+
};
|
|
226
|
+
if (reread && same(whatItSays(control), whatItSays(reread)))
|
|
227
|
+
return source.slice(element.openEnd, element.closeStart);
|
|
228
|
+
if (!pr || !reread || pr.openEnd === pr.end)
|
|
229
|
+
return newProperties(control, this.#freshId(), ns) + after;
|
|
230
|
+
return patched(source, pr, control, reread) + after;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controls.js","sourceRoot":"","sources":["../../src/export/controls.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAmB,GAAG,EAAE,MAAM,aAAa,CAAC;AAElF,+FAA+F;AAC/F,MAAM,KAAK,GAAG;IACZ,KAAK;IACL,OAAO;IACP,KAAK;IACL,IAAI;IACJ,MAAM;IACN,aAAa;IACb,WAAW;IACX,eAAe;IACf,aAAa;IACb,OAAO;IACP,UAAU;CACX,CAAC;AACF,MAAM,EAAE,GAAG,8CAA8C,CAAC;AAQ1D,MAAM,QAAQ,GAAG,CAAC,KAAwC,EAAE,EAAE,CAC5D,KAAK;KACF,GAAG,CAA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,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IACtD,CAAC;CACF"}
|
package/dist/export/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* the relationships new hyperlinks need); every other part is copied from the original package
|
|
5
5
|
* byte for byte. Without a package, a new one is made.
|
|
6
6
|
*/
|
|
7
|
-
import { type FoliDocument, type ResourceJSON } from "@folijs/core";
|
|
7
|
+
import { type Extension, type FoliDocument, type ResourceJSON } from "@folijs/core";
|
|
8
8
|
import { type DocxPackage } from "../package.js";
|
|
9
9
|
export interface ExportOptions {
|
|
10
10
|
/**
|
|
@@ -17,10 +17,16 @@ export interface ExportOptions {
|
|
|
17
17
|
* URL for (an app's upload, by its URL). Undefined: the export fails, never drops it.
|
|
18
18
|
*/
|
|
19
19
|
resource?: (key: string, resource: ResourceJSON) => Promise<Uint8Array | undefined> | Uint8Array | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The custom node and mark types the document may hold (ADR-0008): validated by them, and a
|
|
22
|
+
* node's text in its content control is their `text(attrs)`. A custom type none declares is
|
|
23
|
+
* written as it was read (a `.docx` control's text, else `[type]`).
|
|
24
|
+
*/
|
|
25
|
+
extensions?: readonly Extension[];
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
28
|
* The document as a `.docx`. With `original` (the package it was imported from), the parts
|
|
23
29
|
* Foli does not edit come back byte for byte and unchanged elements verbatim.
|
|
24
30
|
*/
|
|
25
|
-
export declare function exportDocx(document: FoliDocument, original?: DocxPackage, options?: ExportOptions): Promise<Uint8Array
|
|
31
|
+
export declare function exportDocx(document: FoliDocument, original?: DocxPackage, options?: ExportOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
26
32
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/export/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/export/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,YAAY,EAGjB,KAAK,YAAY,EAGlB,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAa,KAAK,WAAW,EAAgB,MAAM,eAAe,CAAC;AAuK1E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CACT,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,YAAY,KACnB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC;IAC9D;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,WAAW,EACtB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAiDlC"}
|
package/dist/export/index.js
CHANGED
|
@@ -4,15 +4,20 @@
|
|
|
4
4
|
* the relationships new hyperlinks need); every other part is copied from the original package
|
|
5
5
|
* byte for byte. Without a package, a new one is made.
|
|
6
6
|
*/
|
|
7
|
-
import { parseDocument } from "@folijs/core";
|
|
8
|
-
import {
|
|
7
|
+
import { parseDocument, } from "@folijs/core";
|
|
8
|
+
import { customToWord } from "../custom.js";
|
|
9
|
+
import { controlsUsed, packageStories } from "../import/index.js";
|
|
10
|
+
import { child, isW, REL, W } from "../import/ooxml.js";
|
|
11
|
+
import { noteIds } from "../import/stories.js";
|
|
9
12
|
import { DocxError } from "../package.js";
|
|
10
|
-
import { newSettingsXml, withTrackRevisions } from "../settings.js";
|
|
13
|
+
import { newSettingsXml, withSettings, withTrackRevisions } from "../settings.js";
|
|
14
|
+
import { parseXml } from "../xml.js";
|
|
11
15
|
import { deflateEntry, writeZip } from "../zip.js";
|
|
16
|
+
import { balanced } from "./balance.js";
|
|
12
17
|
import { blocksXml } from "./content.js";
|
|
13
|
-
import { commentsExtendedXml, commentsXml, numberingXml, stylesXml, } from "./parts.js";
|
|
18
|
+
import { commentsExtendedXml, commentsXml, notesXml, numberingXml, stylesXml, wrapPart, } from "./parts.js";
|
|
14
19
|
import { drawingXml, Media, pictureBytes } from "./pictures.js";
|
|
15
|
-
import { sectionXml } from "./properties.js";
|
|
20
|
+
import { same, sectionXml } from "./properties.js";
|
|
16
21
|
import { DEFAULT_NAMESPACES, escapeAttribute, NEW_ROOT_ATTRIBUTES, namespacesOf, } from "./xmlout.js";
|
|
17
22
|
const CT = {
|
|
18
23
|
main: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
|
|
@@ -21,6 +26,10 @@ const CT = {
|
|
|
21
26
|
comments: "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
|
|
22
27
|
commentsExtended: "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
|
|
23
28
|
settings: "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
|
|
29
|
+
header: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
|
|
30
|
+
footer: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
|
|
31
|
+
footnotes: "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml",
|
|
32
|
+
endnotes: "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml",
|
|
24
33
|
rels: "application/vnd.openxmlformats-package.relationships+xml",
|
|
25
34
|
};
|
|
26
35
|
const encoder = new TextEncoder();
|
|
@@ -74,11 +83,14 @@ class Relationships {
|
|
|
74
83
|
return known;
|
|
75
84
|
return this.add(REL.hyperlink, href, true);
|
|
76
85
|
}
|
|
77
|
-
|
|
86
|
+
/** Adds a relationship; `wanted` is its id (a story's), refused if another has it. */
|
|
87
|
+
add(type, target, external, wanted) {
|
|
88
|
+
if (wanted !== undefined && this.#ids.has(wanted))
|
|
89
|
+
throw new DocxError(`Relationship id ${wanted} is already in use`);
|
|
78
90
|
let n = this.#ids.size + 1;
|
|
79
91
|
while (this.#ids.has(`rId${n}`))
|
|
80
92
|
n++;
|
|
81
|
-
const id = `rId${n}`;
|
|
93
|
+
const id = wanted ?? `rId${n}`;
|
|
82
94
|
this.#ids.add(id);
|
|
83
95
|
this.added.push({ id, type, target, external });
|
|
84
96
|
if (type === REL.hyperlink && external)
|
|
@@ -103,6 +115,7 @@ const REL_IMAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relatio
|
|
|
103
115
|
function contextFor(namespaces, relationships, media, source) {
|
|
104
116
|
return {
|
|
105
117
|
namespaces,
|
|
118
|
+
controls: media.controls,
|
|
106
119
|
hyperlink: (href, id) => relationships.hyperlink(href, id),
|
|
107
120
|
picture: (attrs) => drawingXml(attrs, {
|
|
108
121
|
image: (part, current) => relationships.image(part, relative(source, part), current),
|
|
@@ -125,25 +138,83 @@ function relative(from, to) {
|
|
|
125
138
|
* Foli does not edit come back byte for byte and unchanged elements verbatim.
|
|
126
139
|
*/
|
|
127
140
|
export async function exportDocx(document, original, options = {}) {
|
|
128
|
-
|
|
141
|
+
// Custom nodes and marks become tagged content controls first (ADR-0008).
|
|
142
|
+
const parsed = parseDocument(document, { extensions: options.extensions ?? [] });
|
|
143
|
+
const doc = balanced(withThreadIds(customToWord(parsed, options.extensions), original), original);
|
|
129
144
|
// Before the app is asked for any picture's bytes.
|
|
130
145
|
const reference = original ? undefined : packageReference(doc);
|
|
131
146
|
if (reference) {
|
|
132
147
|
throw new DocxError(`The document refers to a part of its original package (${reference}): export it with that package`);
|
|
133
148
|
}
|
|
149
|
+
const referenced = noteReferences(doc);
|
|
150
|
+
const read = original && (doc.stories || referenced.modeled.size)
|
|
151
|
+
? packageStories(original)
|
|
152
|
+
: { stories: {}, controls: new Map() };
|
|
153
|
+
const originals = read.stories;
|
|
154
|
+
// A story is unchanged if its tree is, and the controls in it say what they said.
|
|
155
|
+
const unchanged = (id) => Object.hasOwn(originals, id) &&
|
|
156
|
+
same(doc.stories?.[id], originals[id]) &&
|
|
157
|
+
[...controlsUsed(doc.stories?.[id])].every((c) => same(doc.controls?.[c], read.controls.get(c)));
|
|
158
|
+
// Notes the model does not hold (an unknown `w:type`) stay in their part: they count too.
|
|
159
|
+
const inPart = original && referenced.modeled.size ? noteIds(original) : new Set();
|
|
160
|
+
for (const key of referenced.modeled)
|
|
161
|
+
if (!Object.hasOwn(doc.stories ?? {}, key) && !inPart.has(key))
|
|
162
|
+
throw new DocxError(`A note reference has no note: ${key.slice(0, 64)}`);
|
|
134
163
|
// The parts written from the model: their drawings are the document's own.
|
|
135
164
|
const rewritten = original
|
|
136
165
|
? [
|
|
137
166
|
original.mainDocument,
|
|
138
167
|
...original
|
|
139
168
|
.relationships(original.mainDocument)
|
|
140
|
-
.filter((r) => r.
|
|
169
|
+
.filter((r) => r.partName &&
|
|
170
|
+
(r.type === REL.comments ||
|
|
171
|
+
(doc.stories && Object.hasOwn(doc.stories, r.id) && !unchanged(r.id))))
|
|
141
172
|
.map((r) => r.partName),
|
|
142
173
|
]
|
|
143
174
|
: [];
|
|
144
175
|
const bytes = await pictureBytes(doc, original, options.resource);
|
|
145
176
|
const media = new Media(doc, original, bytes, rewritten);
|
|
146
|
-
return original
|
|
177
|
+
return original
|
|
178
|
+
? intoPackage(doc, original, originals, unchanged, referenced.isReferenced, options, media)
|
|
179
|
+
: newPackage(doc, referenced.isReferenced, options, media);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The notes the document refers to, as story ids: `modeled` by `noteReference` nodes. `isReferenced`
|
|
183
|
+
* also says yes to every note of a kind that verbatim XML refers to: which one it means is not
|
|
184
|
+
* worth guessing, and removing a note still referred to makes Word refuse the file.
|
|
185
|
+
*/
|
|
186
|
+
function noteReferences(doc) {
|
|
187
|
+
const modeled = new Set();
|
|
188
|
+
const verbatim = new Set();
|
|
189
|
+
JSON.stringify([doc.content, doc.comments, doc.stories], (key, value) => {
|
|
190
|
+
if (key === "xml" && typeof value === "string")
|
|
191
|
+
for (const [, kind] of value.matchAll(/(foot|end)noteReference/g))
|
|
192
|
+
verbatim.add(`${kind}note`);
|
|
193
|
+
const node = value;
|
|
194
|
+
if (node?.type === "noteReference" && typeof node.attrs?.story === "string")
|
|
195
|
+
modeled.add(node.attrs.story);
|
|
196
|
+
return value;
|
|
197
|
+
});
|
|
198
|
+
return {
|
|
199
|
+
modeled,
|
|
200
|
+
isReferenced: (key) => modeled.has(key) || verbatim.has(key.split(":")[0]),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** `text` if it is a well-formed part whose `w:` content is WordprocessingML; DocxError if not. */
|
|
204
|
+
function checkedPart(name, text) {
|
|
205
|
+
let root;
|
|
206
|
+
try {
|
|
207
|
+
root = parseXml(text).root;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
throw new DocxError(`${name}: its namespaces do not fit what is written: ${error}`, {
|
|
211
|
+
cause: error,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
for (const child of root.children)
|
|
215
|
+
if (child.kind === "element" && child.prefix === "w" && child.ns !== W)
|
|
216
|
+
throw new DocxError(`${name}: its w: prefix is not WordprocessingML`);
|
|
217
|
+
return text;
|
|
147
218
|
}
|
|
148
219
|
const PARA_ID = "w14:paraId";
|
|
149
220
|
/** A comment's last paragraph's `w14:paraId`: what `commentsExtended` keys its thread state by. */
|
|
@@ -200,7 +271,23 @@ function withThreadIds(doc, pkg) {
|
|
|
200
271
|
}
|
|
201
272
|
return copy;
|
|
202
273
|
}
|
|
203
|
-
|
|
274
|
+
/** A free name for a new part: `/word/header1.xml`, `/word/header2.xml`… */
|
|
275
|
+
function freePart(stem, taken) {
|
|
276
|
+
let n = 1;
|
|
277
|
+
while (taken(`/word/${stem}${n}.xml`))
|
|
278
|
+
n++;
|
|
279
|
+
return `/word/${stem}${n}.xml`;
|
|
280
|
+
}
|
|
281
|
+
const HEADER_FOOTER = {
|
|
282
|
+
header: { root: "w:hdr", rel: REL.header, contentType: CT.header },
|
|
283
|
+
footer: { root: "w:ftr", rel: REL.footer, contentType: CT.footer },
|
|
284
|
+
};
|
|
285
|
+
const NOTES = {
|
|
286
|
+
footnote: { rel: REL.footnotes, contentType: CT.footnotes, name: "/word/footnotes.xml" },
|
|
287
|
+
endnote: { rel: REL.endnotes, contentType: CT.endnotes, name: "/word/endnotes.xml" },
|
|
288
|
+
};
|
|
289
|
+
const NOTE_KINDS = ["footnote", "endnote"];
|
|
290
|
+
async function intoPackage(doc, pkg, originals, unchanged, isReferenced, options, media) {
|
|
204
291
|
const mainName = pkg.mainDocument;
|
|
205
292
|
const main = pkg.xml(mainName);
|
|
206
293
|
const body = child(main.root, "body");
|
|
@@ -261,9 +348,79 @@ async function intoPackage(doc, pkg, options, media) {
|
|
|
261
348
|
if (comments && changedThreads(doc, pkg)) {
|
|
262
349
|
part(REL.commentsExtended, "/word/commentsExtended.xml", CT.commentsExtended, (o) => commentsExtendedXml(doc, o), true);
|
|
263
350
|
}
|
|
351
|
+
// Stories: none in the document (schema v4, or none read) leaves their parts as they are.
|
|
352
|
+
const stories = doc.stories ?? {};
|
|
353
|
+
const ownRelationships = (name, existing) => new Relationships(existing ? pkg.relationships(name) : []);
|
|
354
|
+
const newNames = new Set();
|
|
355
|
+
const writtenStories = new Map();
|
|
356
|
+
for (const [id, story] of Object.entries(stories)) {
|
|
357
|
+
if (story.kind !== "header" && story.kind !== "footer")
|
|
358
|
+
continue;
|
|
359
|
+
const { root, rel, contentType } = HEADER_FOOTER[story.kind];
|
|
360
|
+
const related = pkg.relationships(mainName).find((r) => r.id === id);
|
|
361
|
+
// Only a part this story was read from: an id can name any relationship of the package.
|
|
362
|
+
if (related && (related.type !== rel || !Object.hasOwn(originals, id)))
|
|
363
|
+
throw new DocxError(`Story ${id.slice(0, 64)} has the id of another relationship`);
|
|
364
|
+
if (!related && !/^[A-Za-z_][\w.-]*$/.test(id))
|
|
365
|
+
throw new DocxError(`Not a relationship id: ${id.slice(0, 64)}`);
|
|
366
|
+
const existing = related?.partName ? pkg.part(related.partName) : undefined;
|
|
367
|
+
if (existing && unchanged(id))
|
|
368
|
+
continue;
|
|
369
|
+
const name = existing?.name ?? freePart(story.kind, (n) => !!pkg.part(n) || newNames.has(n));
|
|
370
|
+
const xml = existing ? pkg.xml(existing.name) : undefined;
|
|
371
|
+
const ns = xml ? namespacesOf(xml.root, xml.source) : namespaces;
|
|
372
|
+
const partRels = ownRelationships(name, !!existing);
|
|
373
|
+
const inner = blocksXml(story.content.content ?? [], contextFor(ns, partRels, media, name));
|
|
374
|
+
const text = checkedPart(name, wrapPart(xml && { root: xml.root, source: xml.source }, root, ns, inner));
|
|
375
|
+
// Two relationships can share a part: both stories must then say the same.
|
|
376
|
+
const earlier = writtenStories.get(name);
|
|
377
|
+
if (earlier !== undefined && earlier !== text)
|
|
378
|
+
throw new DocxError(`${name} is shared by stories that differ`);
|
|
379
|
+
writtenStories.set(name, text);
|
|
380
|
+
if (existing)
|
|
381
|
+
set(name, text);
|
|
382
|
+
else {
|
|
383
|
+
newNames.add(name);
|
|
384
|
+
add.push({ name, data: encoder.encode(text), contentType });
|
|
385
|
+
rels.add(rel, relative(mainName, name), false, id);
|
|
386
|
+
}
|
|
387
|
+
if (partRels.added.length)
|
|
388
|
+
writeRelationships(name, partRels);
|
|
389
|
+
}
|
|
390
|
+
for (const kind of NOTE_KINDS) {
|
|
391
|
+
const { rel, contentType, name: defaultName } = NOTES[kind];
|
|
392
|
+
const name = pkg.relationships(mainName).find((r) => r.type === rel)?.partName;
|
|
393
|
+
const held = Object.values(stories).some((s) => s.kind === kind);
|
|
394
|
+
if (!name && !held)
|
|
395
|
+
continue;
|
|
396
|
+
if (name && !doc.stories)
|
|
397
|
+
continue;
|
|
398
|
+
const target = name ?? defaultName;
|
|
399
|
+
if (name && !isW(pkg.xml(name).root, `${kind}s`)) {
|
|
400
|
+
if (held)
|
|
401
|
+
throw new DocxError(`${name} is not a ${kind}s part`);
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
const partRels = ownRelationships(target, !!name);
|
|
405
|
+
const write = (o, ns) => checkedPart(target, notesXml(kind, stories, originals, unchanged, isReferenced, o, {
|
|
406
|
+
...contextFor(ns, partRels, media, target),
|
|
407
|
+
note: kind,
|
|
408
|
+
}));
|
|
409
|
+
part(rel, defaultName, contentType, write, held);
|
|
410
|
+
if (partRels.added.length)
|
|
411
|
+
writeRelationships(target, partRels);
|
|
412
|
+
}
|
|
264
413
|
const { trackRevisions } = options;
|
|
265
|
-
|
|
266
|
-
|
|
414
|
+
const { settings } = doc;
|
|
415
|
+
if (trackRevisions !== undefined || settings) {
|
|
416
|
+
part(REL.settings, "/word/settings.xml", CT.settings, (o) => {
|
|
417
|
+
if (!o)
|
|
418
|
+
return newSettingsXml(!!trackRevisions, settings);
|
|
419
|
+
const source = trackRevisions === undefined
|
|
420
|
+
? o.source
|
|
421
|
+
: withTrackRevisions(o.source, o.root, trackRevisions);
|
|
422
|
+
return settings ? withSettings(source, parseXml(source).root, settings) : source;
|
|
423
|
+
}, !!trackRevisions || !!settings);
|
|
267
424
|
}
|
|
268
425
|
if (rels.added.length)
|
|
269
426
|
writeRelationships(mainName, rels);
|
|
@@ -316,7 +473,7 @@ function changedThreads(doc, pkg) {
|
|
|
316
473
|
return false;
|
|
317
474
|
}
|
|
318
475
|
/** A new package: content types, relationships, the document and the parts it needs. */
|
|
319
|
-
async function newPackage(doc, options, media) {
|
|
476
|
+
async function newPackage(doc, isReferenced, options, media) {
|
|
320
477
|
const rels = new Relationships([]);
|
|
321
478
|
const context = contextFor(DEFAULT_NAMESPACES, rels, media, "/word/document.xml");
|
|
322
479
|
const main = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n<w:document ${NEW_ROOT_ATTRIBUTES}><w:body>${blocksXml(doc.content.content ?? [], context)}${bodySection(doc, DEFAULT_NAMESPACES)}</w:body></w:document>`;
|
|
@@ -331,6 +488,45 @@ async function newPackage(doc, options, media) {
|
|
|
331
488
|
if (doc.numbering.abstracts.length + doc.numbering.instances.length) {
|
|
332
489
|
add("/word/numbering.xml", REL.numbering, CT.numbering, numberingXml(doc, undefined, DEFAULT_NAMESPACES));
|
|
333
490
|
}
|
|
491
|
+
for (const [id, story] of Object.entries(doc.stories ?? {})) {
|
|
492
|
+
if (story.kind !== "header" && story.kind !== "footer")
|
|
493
|
+
continue;
|
|
494
|
+
if (!/^[A-Za-z_][\w.-]*$/.test(id))
|
|
495
|
+
throw new DocxError(`Not a relationship id: ${id.slice(0, 64)}`);
|
|
496
|
+
const { root, rel, contentType } = HEADER_FOOTER[story.kind];
|
|
497
|
+
const name = freePart(story.kind, (n) => parts.some((p) => p.name === n));
|
|
498
|
+
const partRels = new Relationships([]);
|
|
499
|
+
const inner = blocksXml(story.content.content ?? [], contextFor(DEFAULT_NAMESPACES, partRels, media, name));
|
|
500
|
+
parts.push({
|
|
501
|
+
name,
|
|
502
|
+
text: wrapPart(undefined, root, DEFAULT_NAMESPACES, inner),
|
|
503
|
+
contentType,
|
|
504
|
+
});
|
|
505
|
+
rels.add(rel, relative("/word/document.xml", name), false, id);
|
|
506
|
+
if (partRels.added.length)
|
|
507
|
+
parts.push({
|
|
508
|
+
name: relationshipsPartName(name),
|
|
509
|
+
text: partRels.xml(undefined),
|
|
510
|
+
contentType: CT.rels,
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
for (const kind of NOTE_KINDS) {
|
|
514
|
+
const stories = doc.stories ?? {};
|
|
515
|
+
if (!Object.values(stories).some((s) => s.kind === kind))
|
|
516
|
+
continue;
|
|
517
|
+
const { rel, contentType, name } = NOTES[kind];
|
|
518
|
+
const partRels = new Relationships([]);
|
|
519
|
+
add(name, rel, contentType, notesXml(kind, stories, {}, () => false, isReferenced, undefined, {
|
|
520
|
+
...contextFor(DEFAULT_NAMESPACES, partRels, media, name),
|
|
521
|
+
note: kind,
|
|
522
|
+
}));
|
|
523
|
+
if (partRels.added.length)
|
|
524
|
+
parts.push({
|
|
525
|
+
name: relationshipsPartName(name),
|
|
526
|
+
text: partRels.xml(undefined),
|
|
527
|
+
contentType: CT.rels,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
334
530
|
if (doc.comments.length) {
|
|
335
531
|
const commentRels = new Relationships([]);
|
|
336
532
|
add("/word/comments.xml", REL.comments, CT.comments, commentsXml(doc, undefined, contextFor(DEFAULT_NAMESPACES, commentRels, media, "/word/comments.xml")));
|
|
@@ -344,8 +540,8 @@ async function newPackage(doc, options, media) {
|
|
|
344
540
|
add("/word/commentsExtended.xml", REL.commentsExtended, CT.commentsExtended, commentsExtendedXml(doc, undefined));
|
|
345
541
|
}
|
|
346
542
|
}
|
|
347
|
-
if (options.trackRevisions)
|
|
348
|
-
add("/word/settings.xml", REL.settings, CT.settings, newSettingsXml());
|
|
543
|
+
if (options.trackRevisions || doc.settings)
|
|
544
|
+
add("/word/settings.xml", REL.settings, CT.settings, newSettingsXml(!!options.trackRevisions, doc.settings));
|
|
349
545
|
parts.push({
|
|
350
546
|
name: "/word/_rels/document.xml.rels",
|
|
351
547
|
text: rels.xml(undefined),
|
|
@@ -387,11 +583,15 @@ function packageReference(doc) {
|
|
|
387
583
|
const sections = [doc.section, ...(doc.content.content ?? []).map((b) => b.attrs?.section)];
|
|
388
584
|
for (const s of sections) {
|
|
389
585
|
const section = s;
|
|
390
|
-
|
|
586
|
+
const ids = [
|
|
587
|
+
...Object.values(section?.headers ?? {}),
|
|
588
|
+
...Object.values(section?.footers ?? {}),
|
|
589
|
+
];
|
|
590
|
+
if (ids.some((id) => !doc.stories || !Object.hasOwn(doc.stories, id)))
|
|
391
591
|
return "a header or footer";
|
|
392
592
|
}
|
|
393
593
|
let found;
|
|
394
|
-
JSON.stringify([doc.content, doc.comments], (key, value) => {
|
|
594
|
+
JSON.stringify([doc.content, doc.comments, doc.stories], (key, value) => {
|
|
395
595
|
if (!found && key === "xml" && typeof value === "string" && /\sr:[A-Za-z]+="/.test(value))
|
|
396
596
|
found = "content kept verbatim";
|
|
397
597
|
const link = value;
|