@docx4j/core-ts 0.5.0 → 0.7.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/NOTICE +4 -0
- package/README.md +92 -4
- package/dist/html/convert.mjs +2 -1
- package/dist/html/elements.mjs +2 -1
- package/dist/model/color/ColorMath.d.mts +29 -0
- package/dist/model/color/ColorMath.mjs +146 -0
- package/dist/model/color/ColorTables.d.mts +6 -0
- package/dist/model/color/ColorTables.mjs +83 -0
- package/dist/model/color/DrawingMLColors.d.mts +52 -0
- package/dist/model/color/DrawingMLColors.mjs +374 -0
- package/dist/model/color/ResolvedColor.d.mts +36 -0
- package/dist/model/color/ResolvedColor.mjs +65 -0
- package/dist/model/color/SpreadsheetColors.d.mts +36 -0
- package/dist/model/color/SpreadsheetColors.mjs +84 -0
- package/dist/model/color/StyleFill.d.mts +28 -0
- package/dist/model/color/StyleFill.mjs +21 -0
- package/dist/model/color/ThemeColors.d.mts +86 -0
- package/dist/model/color/ThemeColors.mjs +304 -0
- package/dist/model/color/WordColors.d.mts +71 -0
- package/dist/model/color/WordColors.mjs +121 -0
- package/dist/model/color/index.d.mts +6 -0
- package/dist/model/color/index.mjs +30 -0
- package/dist/model/content/Body.d.mts +145 -23
- package/dist/model/content/Body.mjs +507 -150
- package/dist/model/content/Comment.d.mts +23 -5
- package/dist/model/content/Comment.mjs +207 -26
- package/dist/model/content/ContentControl.d.mts +198 -19
- package/dist/model/content/ContentControl.mjs +672 -99
- package/dist/model/content/Font.d.mts +70 -17
- package/dist/model/content/Font.mjs +119 -36
- package/dist/model/content/InlinePicture.d.mts +11 -0
- package/dist/model/content/InlinePicture.mjs +21 -1
- package/dist/model/content/List.d.mts +6 -3
- package/dist/model/content/List.mjs +18 -8
- package/dist/model/content/Paragraph.d.mts +200 -14
- package/dist/model/content/Paragraph.mjs +898 -82
- package/dist/model/content/Range.d.mts +227 -12
- package/dist/model/content/Range.mjs +785 -59
- package/dist/model/content/ResolvedView.d.mts +104 -0
- package/dist/model/content/ResolvedView.mjs +596 -0
- package/dist/model/content/Table.d.mts +29 -3
- package/dist/model/content/Table.mjs +135 -49
- package/dist/model/content/TrackedChange.d.mts +174 -15
- package/dist/model/content/TrackedChange.mjs +734 -170
- package/dist/model/content/comments.d.mts +20 -6
- package/dist/model/content/comments.mjs +67 -57
- package/dist/model/content/generalException.d.mts +18 -0
- package/dist/model/content/generalException.mjs +24 -0
- package/dist/model/content/index.d.mts +10 -3
- package/dist/model/content/index.mjs +10 -2
- package/dist/model/content/mathText.d.mts +21 -0
- package/dist/model/content/mathText.mjs +267 -0
- package/dist/model/content/officeText.d.mts +27 -0
- package/dist/model/content/officeText.mjs +74 -0
- package/dist/model/content/ooxml.mjs +12 -1
- package/dist/model/content/outline.d.mts +5 -0
- package/dist/model/content/outline.mjs +13 -0
- package/dist/model/content/paraIds.d.mts +5 -0
- package/dist/model/content/paraIds.mjs +54 -0
- package/dist/model/content/placeholders.d.mts +110 -0
- package/dist/model/content/placeholders.mjs +253 -0
- package/dist/model/content/search.d.mts +74 -0
- package/dist/model/content/search.mjs +255 -9
- package/dist/model/content/spanEdits.d.mts +159 -0
- package/dist/model/content/spanEdits.mjs +728 -0
- package/dist/model/content/story.d.mts +47 -0
- package/dist/model/content/story.mjs +95 -0
- package/dist/model/content/tableColumns.d.mts +1 -1
- package/dist/model/content/tableColumns.mjs +108 -80
- package/dist/model/content/tableRevisions.d.mts +11 -3
- package/dist/model/content/tableRevisions.mjs +72 -42
- package/dist/model/content/tableRules.d.mts +30 -0
- package/dist/model/content/tableRules.mjs +102 -0
- package/dist/model/content/textBoxes.d.mts +18 -0
- package/dist/model/content/textBoxes.mjs +105 -0
- package/dist/model/content/trackedChangeFilter.d.mts +39 -0
- package/dist/model/content/trackedChangeFilter.mjs +81 -0
- package/dist/model/content/tracking.d.mts +63 -6
- package/dist/model/content/tracking.mjs +242 -22
- package/dist/model/content/tree.d.mts +172 -24
- package/dist/model/content/tree.mjs +328 -54
- package/dist/model/content/wordRange.d.mts +48 -0
- package/dist/model/content/wordRange.mjs +97 -0
- package/dist/model/customxml/CustomXmlPartCollection.d.mts +30 -1
- package/dist/model/customxml/CustomXmlPartCollection.mjs +81 -12
- package/dist/model/customxml/XmlMapping.d.mts +32 -8
- package/dist/model/customxml/XmlMapping.mjs +64 -10
- package/dist/model/customxml/bindings.d.mts +33 -4
- package/dist/model/customxml/bindings.mjs +171 -45
- package/dist/model/customxml/index.d.mts +1 -0
- package/dist/model/customxml/index.mjs +1 -0
- package/dist/model/customxml/kinds.d.mts +8 -3
- package/dist/model/customxml/kinds.mjs +26 -5
- package/dist/model/customxml/opendope.d.mts +4 -1
- package/dist/model/customxml/opendope.mjs +9 -6
- package/dist/model/customxml/picturePlaceholder.d.mts +17 -0
- package/dist/model/customxml/picturePlaceholder.mjs +32 -0
- package/dist/model/customxml/pictures.d.mts +4 -3
- package/dist/model/customxml/pictures.mjs +22 -8
- package/dist/model/customxml/storeItems.d.mts +57 -0
- package/dist/model/customxml/storeItems.mjs +122 -0
- package/dist/model/customxml/xhtml.mjs +23 -22
- package/dist/model/dateZone.d.mts +25 -0
- package/dist/model/dateZone.mjs +57 -0
- package/dist/model/index.d.mts +3 -0
- package/dist/model/index.mjs +5 -0
- package/dist/model/listnumbering/Emulator.d.mts +37 -5
- package/dist/model/listnumbering/Emulator.mjs +63 -9
- package/dist/model/properties/PropertyResolver.d.mts +74 -2
- package/dist/model/properties/PropertyResolver.mjs +133 -5
- package/dist/model/properties/catalogue.d.mts +19 -5
- package/dist/model/properties/catalogue.mjs +41 -15
- package/dist/model/properties/index.d.mts +1 -1
- package/dist/model/properties/log.d.mts +1 -1
- package/dist/model/properties/log.mjs +5 -5
- package/dist/model/properties/styleUtil.d.mts +3 -1
- package/dist/model/properties/styleUtil.mjs +20 -24
- package/dist/model/properties/table.mjs +4 -2
- package/dist/model/text/CaseMapping.d.mts +38 -0
- package/dist/model/text/CaseMapping.mjs +86 -0
- package/dist/model/text/Extractor.d.mts +349 -0
- package/dist/model/text/Extractor.mjs +2406 -0
- package/dist/model/text/LinkTargets.d.mts +45 -0
- package/dist/model/text/LinkTargets.mjs +170 -0
- package/dist/model/text/MarkdownExporter.d.mts +140 -0
- package/dist/model/text/MarkdownExporter.mjs +255 -0
- package/dist/model/text/PlainText.d.mts +29 -0
- package/dist/model/text/PlainText.mjs +542 -0
- package/dist/model/text/TextContext.d.mts +256 -0
- package/dist/model/text/TextContext.mjs +600 -0
- package/dist/model/text/TextOptions.d.mts +233 -0
- package/dist/model/text/TextOptions.mjs +419 -0
- package/dist/model/text/TextResult.d.mts +621 -0
- package/dist/model/text/TextResult.mjs +629 -0
- package/dist/model/text/Texts.d.mts +99 -0
- package/dist/model/text/Texts.mjs +187 -0
- package/dist/model/text/WmlToMarkdown.d.mts +120 -0
- package/dist/model/text/WmlToMarkdown.mjs +936 -0
- package/dist/model/text/caseMapping.generated.d.mts +7 -0
- package/dist/model/text/caseMapping.generated.mjs +214 -0
- package/dist/model/text/commonmark.d.mts +121 -0
- package/dist/model/text/commonmark.mjs +655 -0
- package/dist/model/text/index.d.mts +8 -0
- package/dist/model/text/index.mjs +9 -0
- package/dist/model/text/normalize.d.mts +8 -0
- package/dist/model/text/normalize.mjs +13 -0
- package/dist/model/text/outline.d.mts +4 -0
- package/dist/model/text/outline.mjs +71 -0
- package/dist/model/wordIntegers.d.mts +29 -0
- package/dist/model/wordIntegers.mjs +78 -0
- package/dist/office-js/document.mjs +15 -1
- package/dist/office-js/fragment.d.mts +7 -5
- package/dist/office-js/fragment.mjs +63 -14
- package/dist/office-js/proxy.d.mts +8 -0
- package/dist/office-js/proxy.mjs +29 -0
- package/dist/office-js/run.mjs +2 -0
- package/dist/office-js/supported.generated.mjs +16 -0
- package/dist/office-js/toApiScript.mjs +29 -12
- package/dist/opc/DirectoryPartStore.d.mts +6 -2
- package/dist/opc/DirectoryPartStore.mjs +11 -4
- package/dist/opc/FlatOpcPartStore.d.mts +4 -2
- package/dist/opc/FlatOpcPartStore.mjs +11 -8
- package/dist/opc/Load.d.mts +32 -0
- package/dist/opc/Load.mjs +115 -5
- package/dist/opc/PartStore.d.mts +34 -1
- package/dist/opc/PartStore.mjs +71 -8
- package/dist/opc/Save.d.mts +32 -0
- package/dist/opc/Save.mjs +110 -4
- package/dist/opc/ZipPartStore.d.mts +4 -2
- package/dist/opc/ZipPartStore.mjs +12 -7
- package/dist/opc/exceptions.d.mts +140 -0
- package/dist/opc/exceptions.mjs +108 -0
- package/dist/opc/index.d.mts +8 -5
- package/dist/opc/index.mjs +5 -3
- package/dist/opc/mce/preprocessor.d.mts +141 -5
- package/dist/opc/mce/preprocessor.mjs +119 -18
- package/dist/opc/mce/understood.d.mts +3 -11
- package/dist/opc/mce/understood.mjs +27 -23
- package/dist/opc/repair/breaks.d.mts +23 -0
- package/dist/opc/repair/breaks.mjs +288 -0
- package/dist/opc/repair/hosts.d.mts +12 -0
- package/dist/opc/repair/hosts.mjs +33 -0
- package/dist/opc/repair/mainRoot.d.mts +19 -0
- package/dist/opc/repair/mainRoot.mjs +168 -0
- package/dist/opc/repair/unknownElements.d.mts +8 -0
- package/dist/opc/repair/unknownElements.mjs +180 -0
- package/dist/opc/repair/wmlNames.generated.d.mts +2 -0
- package/dist/opc/repair/wmlNames.generated.mjs +80 -0
- package/dist/opc/skipped.d.mts +50 -0
- package/dist/opc/skipped.mjs +140 -0
- package/dist/packages/OpcPackage.d.mts +110 -4
- package/dist/packages/OpcPackage.mjs +123 -7
- package/dist/packages/WordprocessingMLPackage.d.mts +45 -8
- package/dist/packages/WordprocessingMLPackage.mjs +158 -21
- package/dist/packages/index.d.mts +1 -1
- package/dist/parts/DefaultXmlPart.mjs +2 -2
- package/dist/parts/Part.d.mts +14 -2
- package/dist/parts/RelationshipsPart.d.mts +15 -0
- package/dist/parts/RelationshipsPart.mjs +66 -1
- package/dist/parts/XmlPart.d.mts +63 -32
- package/dist/parts/XmlPart.mjs +240 -96
- package/dist/parts/wml/comments.mjs +30 -0
- package/dist/parts/wml/index.d.mts +12 -1
- package/dist/parts/wml/index.mjs +37 -1
- package/dist/xml/dom.d.mts +7 -0
- package/dist/xml/dom.mjs +18 -0
- 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' ? ' ' : `\\${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('	');
|
|
592
|
+
literal = literal.substring(1);
|
|
593
|
+
}
|
|
594
|
+
else if (c === ' ') {
|
|
595
|
+
w.raw(' ');
|
|
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,8 @@
|
|
|
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, type TextDropCaps, type TextSmallCaps, type TextRepair, type TextProfile, } 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, type TextVerticalAlignment, } from './TextResult.mjs';
|
|
5
|
+
export { PlainText, INDENT_SPACES, LISTED_FORMAT_NOTE } from './PlainText.mjs';
|
|
6
|
+
export { CaseMapping } from './CaseMapping.mjs';
|
|
7
|
+
export { LinkTargets } from './LinkTargets.mjs';
|
|
8
|
+
export { MarkdownExporter, MarkdownExportOptions, type MarkdownExportOptionsInit, type MarkdownImage, type MarkdownImageDestination, type MarkdownBlock, type MarkdownBlocks, } from './MarkdownExporter.mjs';
|
|
@@ -0,0 +1,9 @@
|
|
|
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 { CaseMapping } from './CaseMapping.mjs';
|
|
8
|
+
export { LinkTargets } from './LinkTargets.mjs';
|
|
9
|
+
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
|
+
}
|