@docx4j/core-ts 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.
Files changed (155) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +32 -4
  3. package/dist/html/convert.mjs +2 -1
  4. package/dist/html/elements.mjs +2 -1
  5. package/dist/model/color/ColorMath.d.mts +29 -0
  6. package/dist/model/color/ColorMath.mjs +146 -0
  7. package/dist/model/color/ColorTables.d.mts +6 -0
  8. package/dist/model/color/ColorTables.mjs +83 -0
  9. package/dist/model/color/DrawingMLColors.d.mts +52 -0
  10. package/dist/model/color/DrawingMLColors.mjs +374 -0
  11. package/dist/model/color/ResolvedColor.d.mts +36 -0
  12. package/dist/model/color/ResolvedColor.mjs +65 -0
  13. package/dist/model/color/SpreadsheetColors.d.mts +36 -0
  14. package/dist/model/color/SpreadsheetColors.mjs +84 -0
  15. package/dist/model/color/StyleFill.d.mts +28 -0
  16. package/dist/model/color/StyleFill.mjs +21 -0
  17. package/dist/model/color/ThemeColors.d.mts +86 -0
  18. package/dist/model/color/ThemeColors.mjs +304 -0
  19. package/dist/model/color/WordColors.d.mts +71 -0
  20. package/dist/model/color/WordColors.mjs +121 -0
  21. package/dist/model/color/index.d.mts +6 -0
  22. package/dist/model/color/index.mjs +30 -0
  23. package/dist/model/content/Body.d.mts +145 -23
  24. package/dist/model/content/Body.mjs +509 -141
  25. package/dist/model/content/Comment.d.mts +21 -3
  26. package/dist/model/content/Comment.mjs +195 -19
  27. package/dist/model/content/ContentControl.d.mts +197 -18
  28. package/dist/model/content/ContentControl.mjs +664 -95
  29. package/dist/model/content/Font.d.mts +67 -17
  30. package/dist/model/content/Font.mjs +114 -35
  31. package/dist/model/content/InlinePicture.d.mts +11 -0
  32. package/dist/model/content/InlinePicture.mjs +21 -1
  33. package/dist/model/content/List.mjs +3 -0
  34. package/dist/model/content/Paragraph.d.mts +189 -13
  35. package/dist/model/content/Paragraph.mjs +870 -74
  36. package/dist/model/content/Range.d.mts +227 -12
  37. package/dist/model/content/Range.mjs +785 -59
  38. package/dist/model/content/ResolvedView.d.mts +104 -0
  39. package/dist/model/content/ResolvedView.mjs +596 -0
  40. package/dist/model/content/Table.d.mts +29 -3
  41. package/dist/model/content/Table.mjs +109 -33
  42. package/dist/model/content/TrackedChange.d.mts +172 -13
  43. package/dist/model/content/TrackedChange.mjs +728 -167
  44. package/dist/model/content/comments.d.mts +20 -6
  45. package/dist/model/content/comments.mjs +67 -57
  46. package/dist/model/content/generalException.d.mts +18 -0
  47. package/dist/model/content/generalException.mjs +24 -0
  48. package/dist/model/content/index.d.mts +8 -3
  49. package/dist/model/content/index.mjs +7 -2
  50. package/dist/model/content/mathText.d.mts +21 -0
  51. package/dist/model/content/mathText.mjs +267 -0
  52. package/dist/model/content/officeText.d.mts +27 -0
  53. package/dist/model/content/officeText.mjs +74 -0
  54. package/dist/model/content/outline.d.mts +5 -0
  55. package/dist/model/content/outline.mjs +13 -0
  56. package/dist/model/content/placeholders.d.mts +110 -0
  57. package/dist/model/content/placeholders.mjs +253 -0
  58. package/dist/model/content/search.d.mts +72 -0
  59. package/dist/model/content/search.mjs +204 -2
  60. package/dist/model/content/spanEdits.d.mts +159 -0
  61. package/dist/model/content/spanEdits.mjs +728 -0
  62. package/dist/model/content/story.d.mts +44 -0
  63. package/dist/model/content/story.mjs +92 -0
  64. package/dist/model/content/tableColumns.d.mts +1 -1
  65. package/dist/model/content/tableColumns.mjs +108 -80
  66. package/dist/model/content/tableRevisions.d.mts +11 -3
  67. package/dist/model/content/tableRevisions.mjs +72 -42
  68. package/dist/model/content/tableRules.d.mts +30 -0
  69. package/dist/model/content/tableRules.mjs +100 -0
  70. package/dist/model/content/textBoxes.d.mts +18 -0
  71. package/dist/model/content/textBoxes.mjs +105 -0
  72. package/dist/model/content/trackedChangeFilter.d.mts +39 -0
  73. package/dist/model/content/trackedChangeFilter.mjs +81 -0
  74. package/dist/model/content/tracking.d.mts +28 -0
  75. package/dist/model/content/tracking.mjs +149 -10
  76. package/dist/model/content/tree.d.mts +171 -22
  77. package/dist/model/content/tree.mjs +329 -53
  78. package/dist/model/customxml/CustomXmlPartCollection.d.mts +8 -0
  79. package/dist/model/customxml/CustomXmlPartCollection.mjs +34 -11
  80. package/dist/model/customxml/XmlMapping.d.mts +1 -1
  81. package/dist/model/customxml/XmlMapping.mjs +11 -0
  82. package/dist/model/customxml/bindings.d.mts +21 -2
  83. package/dist/model/customxml/bindings.mjs +76 -32
  84. package/dist/model/customxml/kinds.d.mts +8 -3
  85. package/dist/model/customxml/kinds.mjs +26 -5
  86. package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
  87. package/dist/model/customxml/picturePlaceholder.mjs +32 -0
  88. package/dist/model/customxml/pictures.d.mts +4 -3
  89. package/dist/model/customxml/pictures.mjs +18 -6
  90. package/dist/model/customxml/xhtml.mjs +8 -2
  91. package/dist/model/index.d.mts +2 -0
  92. package/dist/model/index.mjs +4 -0
  93. package/dist/model/listnumbering/Emulator.d.mts +37 -5
  94. package/dist/model/listnumbering/Emulator.mjs +63 -9
  95. package/dist/model/properties/PropertyResolver.d.mts +60 -1
  96. package/dist/model/properties/PropertyResolver.mjs +115 -2
  97. package/dist/model/properties/catalogue.d.mts +19 -5
  98. package/dist/model/properties/catalogue.mjs +41 -15
  99. package/dist/model/properties/log.d.mts +1 -1
  100. package/dist/model/properties/log.mjs +5 -5
  101. package/dist/model/properties/table.mjs +4 -2
  102. package/dist/model/text/Extractor.d.mts +289 -0
  103. package/dist/model/text/Extractor.mjs +2162 -0
  104. package/dist/model/text/LinkTargets.d.mts +45 -0
  105. package/dist/model/text/LinkTargets.mjs +170 -0
  106. package/dist/model/text/MarkdownExporter.d.mts +140 -0
  107. package/dist/model/text/MarkdownExporter.mjs +255 -0
  108. package/dist/model/text/PlainText.d.mts +29 -0
  109. package/dist/model/text/PlainText.mjs +539 -0
  110. package/dist/model/text/TextContext.d.mts +161 -0
  111. package/dist/model/text/TextContext.mjs +425 -0
  112. package/dist/model/text/TextOptions.d.mts +150 -0
  113. package/dist/model/text/TextOptions.mjs +278 -0
  114. package/dist/model/text/TextResult.d.mts +504 -0
  115. package/dist/model/text/TextResult.mjs +526 -0
  116. package/dist/model/text/Texts.d.mts +99 -0
  117. package/dist/model/text/Texts.mjs +187 -0
  118. package/dist/model/text/WmlToMarkdown.d.mts +120 -0
  119. package/dist/model/text/WmlToMarkdown.mjs +911 -0
  120. package/dist/model/text/commonmark.d.mts +121 -0
  121. package/dist/model/text/commonmark.mjs +655 -0
  122. package/dist/model/text/index.d.mts +7 -0
  123. package/dist/model/text/index.mjs +8 -0
  124. package/dist/model/text/normalize.d.mts +8 -0
  125. package/dist/model/text/normalize.mjs +13 -0
  126. package/dist/model/text/outline.d.mts +4 -0
  127. package/dist/model/text/outline.mjs +71 -0
  128. package/dist/office-js/fragment.d.mts +7 -5
  129. package/dist/office-js/fragment.mjs +63 -14
  130. package/dist/office-js/proxy.d.mts +8 -0
  131. package/dist/office-js/proxy.mjs +29 -0
  132. package/dist/office-js/run.mjs +2 -0
  133. package/dist/office-js/supported.generated.mjs +16 -0
  134. package/dist/office-js/toApiScript.mjs +21 -5
  135. package/dist/opc/Save.d.mts +17 -0
  136. package/dist/opc/Save.mjs +12 -2
  137. package/dist/opc/index.d.mts +3 -3
  138. package/dist/opc/index.mjs +1 -1
  139. package/dist/opc/mce/preprocessor.d.mts +28 -3
  140. package/dist/opc/mce/preprocessor.mjs +4 -4
  141. package/dist/opc/mce/understood.d.mts +30 -6
  142. package/dist/opc/mce/understood.mjs +37 -7
  143. package/dist/packages/OpcPackage.d.mts +13 -0
  144. package/dist/packages/OpcPackage.mjs +1 -0
  145. package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
  146. package/dist/packages/WordprocessingMLPackage.mjs +155 -20
  147. package/dist/parts/DefaultXmlPart.mjs +2 -2
  148. package/dist/parts/Part.d.mts +10 -2
  149. package/dist/parts/XmlPart.d.mts +12 -30
  150. package/dist/parts/XmlPart.mjs +44 -93
  151. package/dist/parts/wml/comments.mjs +30 -0
  152. package/dist/parts/wml/index.mjs +12 -0
  153. package/dist/xml/dom.d.mts +7 -0
  154. package/dist/xml/dom.mjs +18 -0
  155. package/package.json +2 -2
@@ -0,0 +1,655 @@
1
+ // CR-012 phase 3: the Markdown writer docx4j's MarkdownExporter serializes with, a port of commonmark-java
2
+ // 0.30.0's org.commonmark.renderer.markdown (MarkdownWriter, CoreMarkdownNodeRenderer) and of the Markdown
3
+ // renderers of its GFM tables, strikethrough and footnotes extensions, with docx4j-markdown's math nodes
4
+ // (org.docx4j.markdown.math.MathExtension's renderer). Only the nodes docx4j's WmlToMarkdown builds are here,
5
+ // and each renders as commonmark-java renders it, so that this package's Markdown is docx4j's byte for byte.
6
+ //
7
+ // commonmark-java's licence, which its ported code keeps:
8
+ //
9
+ // Copyright (c) 2015, Atlassian Pty Ltd
10
+ // All rights reserved.
11
+ //
12
+ // Redistribution and use in source and binary forms, with or without
13
+ // modification, are permitted provided that the following conditions are met:
14
+ //
15
+ // * Redistributions of source code must retain the above copyright notice, this
16
+ // list of conditions and the following disclaimer.
17
+ //
18
+ // * Redistributions in binary form must reproduce the above copyright notice,
19
+ // this list of conditions and the following disclaimer in the documentation
20
+ // and/or other materials provided with the distribution.
21
+ //
22
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+ // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+ // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ // ---------------------------------------------------------------- nodes (org.commonmark.node and the extensions')
33
+ /** A node of the Markdown tree: its parent and children (commonmark-java `Node`). */
34
+ export class MdNode {
35
+ constructor() {
36
+ this.children = [];
37
+ }
38
+ get firstChild() {
39
+ return this.children[0];
40
+ }
41
+ get lastChild() {
42
+ return this.children[this.children.length - 1];
43
+ }
44
+ get previous() {
45
+ var _a;
46
+ const siblings = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.children;
47
+ return siblings === undefined ? undefined : siblings[siblings.indexOf(this) - 1];
48
+ }
49
+ get next() {
50
+ var _a;
51
+ const siblings = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.children;
52
+ if (siblings === undefined)
53
+ return undefined;
54
+ const i = siblings.indexOf(this);
55
+ return i < 0 ? undefined : siblings[i + 1];
56
+ }
57
+ appendChild(child) {
58
+ child.unlink();
59
+ child.parent = this;
60
+ this.children.push(child);
61
+ }
62
+ prependChild(child) {
63
+ child.unlink();
64
+ child.parent = this;
65
+ this.children.unshift(child);
66
+ }
67
+ unlink() {
68
+ if (this.parent === undefined)
69
+ return;
70
+ const i = this.parent.children.indexOf(this);
71
+ if (i >= 0)
72
+ this.parent.children.splice(i, 1);
73
+ this.parent = undefined;
74
+ }
75
+ }
76
+ export class MdDocument extends MdNode {
77
+ }
78
+ export class MdParagraph extends MdNode {
79
+ }
80
+ export class MdBlockQuote extends MdNode {
81
+ }
82
+ export class MdHardLineBreak extends MdNode {
83
+ }
84
+ export class MdStrongEmphasis extends MdNode {
85
+ }
86
+ export class MdTableBlock extends MdNode {
87
+ }
88
+ export class MdTableHead extends MdNode {
89
+ }
90
+ export class MdTableBody extends MdNode {
91
+ }
92
+ export class MdTableRow extends MdNode {
93
+ }
94
+ export class MdHeading extends MdNode {
95
+ constructor(level) {
96
+ super();
97
+ this.level = level;
98
+ }
99
+ }
100
+ /** A bullet or ordered list: tight when its items are not separated by blank lines. */
101
+ export class MdListBlock extends MdNode {
102
+ constructor() {
103
+ super(...arguments);
104
+ this.tight = true;
105
+ }
106
+ }
107
+ export class MdBulletList extends MdListBlock {
108
+ }
109
+ export class MdOrderedList extends MdListBlock {
110
+ }
111
+ export class MdListItem extends MdNode {
112
+ }
113
+ export class MdFencedCodeBlock extends MdNode {
114
+ constructor(literal) {
115
+ super();
116
+ this.literal = literal;
117
+ }
118
+ }
119
+ export class MdThematicBreak extends MdNode {
120
+ constructor(literal) {
121
+ super();
122
+ this.literal = literal;
123
+ }
124
+ }
125
+ export class MdHtmlInline extends MdNode {
126
+ constructor(literal) {
127
+ super();
128
+ this.literal = literal;
129
+ }
130
+ }
131
+ export class MdText extends MdNode {
132
+ constructor(literal) {
133
+ super();
134
+ this.literal = literal;
135
+ }
136
+ }
137
+ export class MdCode extends MdNode {
138
+ constructor(literal) {
139
+ super();
140
+ this.literal = literal;
141
+ }
142
+ }
143
+ export class MdEmphasis extends MdNode {
144
+ }
145
+ export class MdLink extends MdNode {
146
+ constructor(destination, title) {
147
+ super();
148
+ this.destination = destination;
149
+ this.title = title;
150
+ }
151
+ }
152
+ export class MdImage extends MdNode {
153
+ constructor(destination, title) {
154
+ super();
155
+ this.destination = destination;
156
+ this.title = title;
157
+ }
158
+ }
159
+ export class MdTableCell extends MdNode {
160
+ constructor(header) {
161
+ super();
162
+ this.header = header;
163
+ }
164
+ }
165
+ export class MdStrikethrough extends MdNode {
166
+ constructor(delimiter) {
167
+ super();
168
+ this.delimiter = delimiter;
169
+ }
170
+ }
171
+ export class MdFootnoteDefinition extends MdNode {
172
+ constructor(label) {
173
+ super();
174
+ this.label = label;
175
+ }
176
+ }
177
+ export class MdFootnoteReference extends MdNode {
178
+ constructor(label) {
179
+ super();
180
+ this.label = label;
181
+ }
182
+ }
183
+ /** Inline math, `$...$` (docx4j `InlineMath`). */
184
+ export class MdInlineMath extends MdNode {
185
+ constructor(literal, displayHint) {
186
+ super();
187
+ this.literal = literal;
188
+ this.displayHint = displayHint;
189
+ }
190
+ }
191
+ /** Display math, a `$$` block (docx4j `DisplayMath`). */
192
+ export class MdDisplayMath extends MdNode {
193
+ constructor(literal) {
194
+ super();
195
+ this.literal = literal;
196
+ }
197
+ }
198
+ const chars = (s) => new Set(s.split(''));
199
+ class MarkdownWriter {
200
+ constructor(starts) {
201
+ this.starts = starts;
202
+ this.out = '';
203
+ this.blockSeparator = 0;
204
+ this.lastChar = '\u0000';
205
+ this.atLineStart = true;
206
+ this.prefixes = [];
207
+ this.tight = [];
208
+ this.rawEscapes = [];
209
+ /** Where the line being written starts in `out`. */
210
+ this.lineStart = 0;
211
+ }
212
+ raw(s) {
213
+ this.flushBlockSeparator();
214
+ this.write(s, undefined, true);
215
+ }
216
+ text(s, escape) {
217
+ if (s === '')
218
+ return;
219
+ this.flushBlockSeparator();
220
+ this.write(s, escape, true);
221
+ }
222
+ line() {
223
+ this.write('\n', undefined, false);
224
+ this.writePrefixes();
225
+ this.atLineStart = true;
226
+ }
227
+ block() {
228
+ this.blockSeparator = this.isTight() ? 1 : 2;
229
+ this.atLineStart = true;
230
+ }
231
+ pushPrefix(prefix) {
232
+ this.prefixes.push(prefix);
233
+ }
234
+ writePrefix(prefix) {
235
+ const tmp = this.atLineStart;
236
+ this.raw(prefix);
237
+ this.atLineStart = tmp;
238
+ }
239
+ popPrefix() {
240
+ this.prefixes.pop();
241
+ }
242
+ pushTight(tight) {
243
+ this.tight.push(tight);
244
+ }
245
+ popTight() {
246
+ this.tight.pop();
247
+ }
248
+ pushRawEscape(escape) {
249
+ this.rawEscapes.push(escape);
250
+ }
251
+ popRawEscape() {
252
+ this.rawEscapes.pop();
253
+ }
254
+ /**
255
+ * Writes `s`, escaping what `escape` and the raw escapes match. Content (`raw`, `text`) starts a pending
256
+ * tag at the line it is written on; line ends, prefixes and block separators never do.
257
+ */
258
+ write(s, escape, content) {
259
+ if (s === '') {
260
+ this.atLineStart = false;
261
+ return;
262
+ }
263
+ if (content && this.pendingTag !== undefined) {
264
+ if (!this.starts.has(this.pendingTag))
265
+ this.starts.set(this.pendingTag, this.lineStart);
266
+ this.pendingTag = undefined;
267
+ }
268
+ let chunk = s;
269
+ if (this.rawEscapes.length > 0 || escape !== undefined) {
270
+ chunk = '';
271
+ for (let i = 0; i < s.length; i++) {
272
+ const c = s.charAt(i);
273
+ if ((escape !== undefined && escape.has(c)) || this.rawEscapes.some((e) => e.has(c))) {
274
+ chunk += c === '\n' ? '&#10;' : `\\${c}`; // a line end can't be escaped with \
275
+ }
276
+ else {
277
+ chunk += c;
278
+ }
279
+ }
280
+ }
281
+ const newline = chunk.lastIndexOf('\n');
282
+ if (newline >= 0)
283
+ this.lineStart = this.out.length + newline + 1;
284
+ this.out += chunk;
285
+ this.lastChar = s.charAt(s.length - 1);
286
+ this.atLineStart = false;
287
+ }
288
+ writePrefixes() {
289
+ for (const prefix of this.prefixes)
290
+ this.write(prefix, undefined, false);
291
+ }
292
+ flushBlockSeparator() {
293
+ if (this.blockSeparator !== 0) {
294
+ this.write('\n', undefined, false);
295
+ this.writePrefixes();
296
+ if (this.blockSeparator > 1) {
297
+ this.write('\n', undefined, false);
298
+ this.writePrefixes();
299
+ }
300
+ this.blockSeparator = 0;
301
+ }
302
+ }
303
+ isTight() {
304
+ return this.tight.length > 0 && this.tight[this.tight.length - 1];
305
+ }
306
+ }
307
+ // ---------------------------------------------------------------- the renderer (CoreMarkdownNodeRenderer and the extensions')
308
+ /**
309
+ * The characters escaped in text: commonmark-java's own, and the extensions' special characters as docx4j
310
+ * registers them (`|` the tables', `~` strikethrough's, `$` docx4j's math); `#` too in a heading.
311
+ */
312
+ const TEXT_ESCAPE = chars('[]<>`*_&\n\\|~$');
313
+ const TEXT_ESCAPE_IN_HEADING = chars('[]<>`*_&\n\\|~$#');
314
+ const LINK_DESTINATION_NEEDS_ANGLE_BRACKETS = chars(' ()<>\n\\');
315
+ const LINK_DESTINATION_ESCAPE_IN_ANGLE_BRACKETS = chars('<>\n\\');
316
+ const LINK_TITLE_ESCAPE_IN_QUOTES = chars('"\n\\');
317
+ const PIPE = chars('|');
318
+ const ORDERED_LIST_MARKER = /^([0-9]{1,9})([.)])/;
319
+ /**
320
+ * Renders a Markdown tree as commonmark-java's `MarkdownRenderer` does, with the tables, strikethrough,
321
+ * footnotes and docx4j math extensions. `starts` receives, for each node with a `tag`, the offset of the
322
+ * line its first character is written on.
323
+ */
324
+ export function renderMarkdown(document, starts = new Map()) {
325
+ const r = new Renderer(new MarkdownWriter(starts));
326
+ r.render(document);
327
+ return r.writer.out;
328
+ }
329
+ class Renderer {
330
+ constructor(writer) {
331
+ this.writer = writer;
332
+ /** The current table's column alignments, from its header cells. */
333
+ this.columns = [];
334
+ }
335
+ render(node) {
336
+ const w = this.writer;
337
+ // a tag whose node wrote nothing gives way to the next; a tag starts once
338
+ const tagged = node.tag !== undefined && !w.starts.has(node.tag);
339
+ if (tagged)
340
+ w.pendingTag = node.tag;
341
+ this.renderNode(node);
342
+ if (tagged && w.pendingTag === node.tag)
343
+ w.pendingTag = undefined;
344
+ }
345
+ renderNode(node) {
346
+ var _a, _b, _c, _d, _e;
347
+ const w = this.writer;
348
+ if (node instanceof MdDocument) {
349
+ this.children(node);
350
+ w.line();
351
+ }
352
+ else if (node instanceof MdThematicBreak) {
353
+ w.raw((_a = node.literal) !== null && _a !== void 0 ? _a : '___'); // ___ isn't ambiguous with a list marker
354
+ w.block();
355
+ }
356
+ else if (node instanceof MdHeading) {
357
+ this.heading(node);
358
+ }
359
+ else if (node instanceof MdFencedCodeBlock) {
360
+ this.fencedCodeBlock(node);
361
+ }
362
+ else if (node instanceof MdParagraph) {
363
+ this.children(node);
364
+ w.block();
365
+ }
366
+ else if (node instanceof MdBlockQuote) {
367
+ w.writePrefix('> ');
368
+ w.pushPrefix('> ');
369
+ this.children(node);
370
+ w.popPrefix();
371
+ w.block();
372
+ }
373
+ else if (node instanceof MdBulletList || node instanceof MdOrderedList) {
374
+ w.pushTight(node.tight);
375
+ this.listHolder = node instanceof MdBulletList
376
+ ? { parent: this.listHolder, marker: (_b = node.marker) !== null && _b !== void 0 ? _b : '-', number: 0, delimiter: undefined }
377
+ : { parent: this.listHolder, marker: '', number: (_c = node.markerStartNumber) !== null && _c !== void 0 ? _c : 1, delimiter: (_d = node.markerDelimiter) !== null && _d !== void 0 ? _d : '.' };
378
+ this.children(node);
379
+ this.listHolder = this.listHolder.parent;
380
+ w.popTight();
381
+ w.block();
382
+ }
383
+ else if (node instanceof MdListItem) {
384
+ this.listItem(node);
385
+ }
386
+ else if (node instanceof MdCode) {
387
+ this.code(node.literal);
388
+ }
389
+ else if (node instanceof MdEmphasis) {
390
+ // nested emphasis takes the other delimiter
391
+ const delimiter = w.lastChar === '*' ? '_' : '*';
392
+ w.raw(delimiter);
393
+ this.children(node);
394
+ w.raw(delimiter);
395
+ }
396
+ else if (node instanceof MdStrongEmphasis) {
397
+ w.raw('**');
398
+ this.children(node);
399
+ w.raw('**');
400
+ }
401
+ else if (node instanceof MdLink) {
402
+ this.linkLike(node.title, node.destination, node, '[');
403
+ }
404
+ else if (node instanceof MdImage) {
405
+ this.linkLike(node.title, node.destination, node, '![');
406
+ }
407
+ else if (node instanceof MdHtmlInline) {
408
+ w.raw(node.literal);
409
+ }
410
+ else if (node instanceof MdHardLineBreak) {
411
+ w.raw(' ');
412
+ w.line();
413
+ }
414
+ else if (node instanceof MdText) {
415
+ this.text(node);
416
+ }
417
+ else if (node instanceof MdTableBlock) {
418
+ this.columns.length = 0;
419
+ w.pushTight(true);
420
+ this.children(node);
421
+ w.popTight();
422
+ w.block();
423
+ }
424
+ else if (node instanceof MdTableHead) {
425
+ this.children(node);
426
+ for (const alignment of this.columns) {
427
+ w.raw('|');
428
+ w.raw(alignment === 'LEFT' ? ':---' : alignment === 'RIGHT' ? '---:' : alignment === 'CENTER' ? ':---:' : '---');
429
+ }
430
+ w.raw('|');
431
+ w.block();
432
+ }
433
+ else if (node instanceof MdTableBody) {
434
+ this.children(node);
435
+ }
436
+ else if (node instanceof MdTableRow) {
437
+ this.children(node);
438
+ w.raw('|'); // the | at the end of the line
439
+ w.block();
440
+ }
441
+ else if (node instanceof MdTableCell) {
442
+ if (((_e = node.parent) === null || _e === void 0 ? void 0 : _e.parent) instanceof MdTableHead)
443
+ this.columns.push(node.alignment);
444
+ w.raw('|');
445
+ w.pushRawEscape(PIPE);
446
+ this.children(node);
447
+ w.popRawEscape();
448
+ }
449
+ else if (node instanceof MdStrikethrough) {
450
+ w.raw(node.delimiter);
451
+ this.children(node);
452
+ w.raw(node.delimiter);
453
+ }
454
+ else if (node instanceof MdFootnoteReference) {
455
+ w.raw('[^');
456
+ w.raw(node.label); // labels are written as they are
457
+ w.raw(']');
458
+ }
459
+ else if (node instanceof MdFootnoteDefinition) {
460
+ w.raw('[^');
461
+ w.raw(node.label);
462
+ w.raw(']: ');
463
+ w.pushPrefix(' ');
464
+ this.children(node);
465
+ w.popPrefix();
466
+ }
467
+ else if (node instanceof MdInlineMath) {
468
+ const delimiter = node.displayHint ? '$$' : '$';
469
+ w.raw(delimiter);
470
+ w.raw(node.literal.replace(/\n/g, ' '));
471
+ w.raw(delimiter);
472
+ }
473
+ else if (node instanceof MdDisplayMath) {
474
+ w.raw('$$');
475
+ w.line();
476
+ for (const line of node.literal.split('\n')) {
477
+ w.raw(line);
478
+ w.line();
479
+ }
480
+ w.raw('$$');
481
+ w.block();
482
+ }
483
+ else {
484
+ throw new Error(`No Markdown renderer for ${node.constructor.name}`);
485
+ }
486
+ }
487
+ children(parent) {
488
+ for (const child of [...parent.children])
489
+ this.render(child);
490
+ }
491
+ heading(heading) {
492
+ const w = this.writer;
493
+ if (heading.level <= 2 && hasLineBreak(heading)) {
494
+ // a Setext heading can have several lines, but only levels 1 and 2
495
+ this.children(heading);
496
+ w.line();
497
+ w.raw(heading.level === 1 ? '===' : '---');
498
+ w.block();
499
+ return;
500
+ }
501
+ w.raw('#'.repeat(heading.level));
502
+ w.raw(' ');
503
+ this.children(heading);
504
+ w.block();
505
+ }
506
+ fencedCodeBlock(code) {
507
+ const w = this.writer;
508
+ const literal = code.literal;
509
+ // a fence longer than any run of backticks in the code
510
+ const fence = '`'.repeat(Math.max(maxRunLength('`', literal) + 1, 3));
511
+ w.raw(fence);
512
+ w.line();
513
+ if (literal !== '') {
514
+ for (const line of linesOf(literal)) {
515
+ w.raw(line);
516
+ w.line();
517
+ }
518
+ }
519
+ w.raw(fence);
520
+ w.block();
521
+ }
522
+ listItem(item) {
523
+ const w = this.writer;
524
+ const holder = this.listHolder;
525
+ if (holder === undefined)
526
+ throw new Error('A list item outside a list');
527
+ let marker;
528
+ if (holder.delimiter === undefined) {
529
+ marker = holder.marker;
530
+ }
531
+ else {
532
+ marker = `${holder.number}${holder.delimiter}`;
533
+ holder.number++;
534
+ }
535
+ const spaces = ' ';
536
+ w.writePrefix(marker);
537
+ w.writePrefix(spaces);
538
+ w.pushPrefix(' '.repeat(marker.length + spaces.length));
539
+ if (item.firstChild === undefined) {
540
+ w.block(); // an empty item
541
+ }
542
+ else {
543
+ this.children(item);
544
+ }
545
+ w.popPrefix();
546
+ }
547
+ code(literal) {
548
+ const w = this.writer;
549
+ // backticks in the code: one more around it
550
+ const backticks = maxRunLength('`', literal);
551
+ w.raw('`'.repeat(backticks + 1));
552
+ // a space inside where the code starts or ends with a backtick, or starts and ends with a space
553
+ const addSpace = literal.startsWith('`') || literal.endsWith('`')
554
+ || (literal.startsWith(' ') && literal.endsWith(' ') && /[^ ]/.test(literal));
555
+ if (addSpace)
556
+ w.raw(' ');
557
+ w.raw(literal);
558
+ if (addSpace)
559
+ w.raw(' ');
560
+ w.raw('`'.repeat(backticks + 1));
561
+ }
562
+ text(text) {
563
+ // When in doubt, escape: a character special only at a line's start is escaped there alone.
564
+ const w = this.writer;
565
+ let literal = text.literal;
566
+ if (w.atLineStart && literal !== '') {
567
+ const c = literal.charAt(0);
568
+ if (c === '-') {
569
+ w.raw('\\-'); // a bullet list marker
570
+ literal = literal.substring(1);
571
+ }
572
+ else if (c === '#') {
573
+ w.raw('\\#'); // an ATX heading
574
+ literal = literal.substring(1);
575
+ }
576
+ else if (c === '=') {
577
+ if (text.previous !== undefined) { // a Setext heading, unless the block's first line
578
+ w.raw('\\=');
579
+ literal = literal.substring(1);
580
+ }
581
+ }
582
+ else if (c >= '0' && c <= '9') {
583
+ const m = ORDERED_LIST_MARKER.exec(literal);
584
+ if (m) {
585
+ w.raw(m[1]);
586
+ w.raw(`\\${m[2]}`);
587
+ literal = literal.substring(m[0].length);
588
+ }
589
+ }
590
+ else if (c === '\t') {
591
+ w.raw('&#9;');
592
+ literal = literal.substring(1);
593
+ }
594
+ else if (c === ' ') {
595
+ w.raw('&#32;');
596
+ literal = literal.substring(1);
597
+ }
598
+ }
599
+ const escape = text.parent instanceof MdHeading ? TEXT_ESCAPE_IN_HEADING : TEXT_ESCAPE;
600
+ if (literal.endsWith('!') && text.next instanceof MdLink) {
601
+ // an unescaped ! would make the link an image
602
+ w.text(literal.substring(0, literal.length - 1), escape);
603
+ w.raw('\\!');
604
+ }
605
+ else {
606
+ w.text(literal, escape);
607
+ }
608
+ }
609
+ linkLike(title, destination, node, opener) {
610
+ const w = this.writer;
611
+ w.raw(opener);
612
+ this.children(node);
613
+ w.raw(']');
614
+ w.raw('(');
615
+ if ([...destination].some((c) => LINK_DESTINATION_NEEDS_ANGLE_BRACKETS.has(c))) {
616
+ w.raw('<');
617
+ w.text(destination, LINK_DESTINATION_ESCAPE_IN_ANGLE_BRACKETS);
618
+ w.raw('>');
619
+ }
620
+ else {
621
+ w.raw(destination);
622
+ }
623
+ if (title !== undefined) {
624
+ w.raw(' ');
625
+ w.raw('"');
626
+ w.text(title, LINK_TITLE_ESCAPE_IN_QUOTES);
627
+ w.raw('"');
628
+ }
629
+ w.raw(')');
630
+ }
631
+ }
632
+ function hasLineBreak(node) {
633
+ return node.children.some((c) => c instanceof MdHardLineBreak || hasLineBreak(c));
634
+ }
635
+ function maxRunLength(needle, s) {
636
+ let max = 0;
637
+ let pos = 0;
638
+ while (pos < s.length) {
639
+ pos = s.indexOf(needle, pos);
640
+ if (pos === -1)
641
+ return max;
642
+ let run = 0;
643
+ do {
644
+ pos += needle.length;
645
+ run++;
646
+ } while (s.startsWith(needle, pos));
647
+ max = Math.max(run, max);
648
+ }
649
+ return max;
650
+ }
651
+ /** A literal's lines, `\n` being a terminator: "abc\n" is one line. */
652
+ function linesOf(literal) {
653
+ const parts = literal.split('\n');
654
+ return parts[parts.length - 1] === '' ? parts.slice(0, -1) : parts;
655
+ }
@@ -0,0 +1,7 @@
1
+ export { Texts } from './Texts.mjs';
2
+ export { TextContext, PackageTrees, type TextPackage } from './TextContext.mjs';
3
+ export { TextOptions, TextOptionError, TEXT_OPTION_NAMES, type TextOptionsInit, type TextModelView, type TextInclude, type TextFields, type TextBindings, type TextSymbols, type TextMath, type TextTables, type TextMarkupDetail, type TextLayout, } from './TextOptions.mjs';
4
+ export { TextResult, TextBlock, TextRun, TextRow, TextCell, TextField, TextNumbering, TextRevision, TextWarning, TextComment, TextImage, ImageDescription, AltTextDescriber, type ImageDescriber, type TextBlockKind, type TextStory, type TextRunKind, type NoteType, type TextRunSource, } from './TextResult.mjs';
5
+ export { PlainText, INDENT_SPACES, LISTED_FORMAT_NOTE } from './PlainText.mjs';
6
+ export { LinkTargets } from './LinkTargets.mjs';
7
+ export { MarkdownExporter, MarkdownExportOptions, type MarkdownExportOptionsInit, type MarkdownImage, type MarkdownImageDestination, type MarkdownBlock, type MarkdownBlocks, } from './MarkdownExporter.mjs';
@@ -0,0 +1,8 @@
1
+ // The text model (CR-012): docx4j's org.docx4j.model.text, held to the text extraction specification.
2
+ export { Texts } from './Texts.mjs';
3
+ export { TextContext, PackageTrees } from './TextContext.mjs';
4
+ export { TextOptions, TextOptionError, TEXT_OPTION_NAMES, } from './TextOptions.mjs';
5
+ export { TextResult, TextBlock, TextRun, TextRow, TextCell, TextField, TextNumbering, TextRevision, TextWarning, TextComment, TextImage, ImageDescription, AltTextDescriber, } from './TextResult.mjs';
6
+ export { PlainText, INDENT_SPACES, LISTED_FORMAT_NOTE } from './PlainText.mjs';
7
+ export { LinkTargets } from './LinkTargets.mjs';
8
+ export { MarkdownExporter, MarkdownExportOptions, } from './MarkdownExporter.mjs';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * WD REQ-1201's normalisation, under which texts are compared (`mce.branches_differ`, REQ-307; the
3
+ * conformance suite): CriticMarkup's delimiters, then white space (Java's `\s`, the six ASCII white-space
4
+ * characters, and `\p{Z}`), `*`, `_`, `\`, `{`, `}` and `$` removed. No Unicode normalisation: zero-width
5
+ * and tag characters, and the hyphens, are kept. JavaScript's `\s` would take U+FEFF too, so the
6
+ * characters are named.
7
+ */
8
+ export declare function normalize(value: string | undefined | null): string;
@@ -0,0 +1,13 @@
1
+ // CR-012 phase 2: WD REQ-1201's normalisation, docx4j's `Texts.normalize`.
2
+ /**
3
+ * WD REQ-1201's normalisation, under which texts are compared (`mce.branches_differ`, REQ-307; the
4
+ * conformance suite): CriticMarkup's delimiters, then white space (Java's `\s`, the six ASCII white-space
5
+ * characters, and `\p{Z}`), `*`, `_`, `\`, `{`, `}` and `$` removed. No Unicode normalisation: zero-width
6
+ * and tag characters, and the hyphens, are kept. JavaScript's `\s` would take U+FEFF too, so the
7
+ * characters are named.
8
+ */
9
+ export function normalize(value) {
10
+ if (value === undefined || value === null)
11
+ return '';
12
+ return value.replace(/\{\+\+|\+\+\}|\{--|--\}|\{>>|<<\}/g, '').replace(/[\t\n\x0B\f\r\p{Z}*_\\{}$]/gu, '');
13
+ }
@@ -0,0 +1,4 @@
1
+ import type { Outline } from '../content/Body.mjs';
2
+ import type { TextBlock } from './TextResult.mjs';
3
+ /** The outline of blocks: each paragraph with its address, paraId, style and text, each table with its size; a cell's blocks after its table. */
4
+ export declare function outlineOfBlocks(blocks: readonly TextBlock[]): Outline;