@elisra-devops/docgen-skins 0.10.2 → 0.10.4
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/bin/index.d.ts +2 -0
- package/bin/index.js +32 -3
- package/bin/index.js.map +1 -1
- package/bin/models/json/JSONRun.d.ts +1 -1
- package/bin/models/json/JSONRun.js +44 -42
- package/bin/models/json/JSONRun.js.map +1 -1
- package/bin/models/json/default.d.ts +1 -1
- package/bin/models/json/default.js +13 -10
- package/bin/models/json/default.js.map +1 -1
- package/bin/models/json/paragraph/JSONRichTextParagraph.d.ts +134 -3
- package/bin/models/json/paragraph/JSONRichTextParagraph.js +325 -58
- package/bin/models/json/paragraph/JSONRichTextParagraph.js.map +1 -1
- package/bin/models/json/wordJsonModels.d.ts +50 -4
- package/package.json +1 -1
- package/src/index.ts +41 -3
- package/src/models/json/JSONRun.ts +46 -43
- package/src/models/json/default.ts +15 -12
- package/src/models/json/paragraph/JSONRichTextParagraph.ts +349 -57
- package/src/models/json/wordJsonModels.ts +62 -4
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Run, WIProperty, StyleOptions } from
|
|
2
|
-
import { defaultJsonRun } from
|
|
3
|
-
import striphtml from
|
|
4
|
-
import logger from
|
|
1
|
+
import { Run, WIProperty, StyleOptions } from './wordJsonModels';
|
|
2
|
+
import { defaultJsonRun } from './default';
|
|
3
|
+
import striphtml from 'string-strip-html';
|
|
4
|
+
import logger from '../../services/logger';
|
|
5
5
|
|
|
6
6
|
const replaceBr = ({ tag, deleteFrom, deleteTo, rangesArr }) => {
|
|
7
7
|
if (tag.name === `br`) {
|
|
8
|
-
rangesArr.push(deleteFrom, deleteTo,
|
|
8
|
+
rangesArr.push(deleteFrom, deleteTo, '\n');
|
|
9
9
|
} else {
|
|
10
|
-
rangesArr.push(deleteFrom, deleteTo,
|
|
10
|
+
rangesArr.push(deleteFrom, deleteTo, ' ');
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -22,53 +22,56 @@ export default class JSONRun {
|
|
|
22
22
|
let runs: Run[] = [];
|
|
23
23
|
let rowArray;
|
|
24
24
|
try {
|
|
25
|
-
rowArray = value.split(
|
|
25
|
+
rowArray = value.split('\n');
|
|
26
26
|
//try iterating the array
|
|
27
27
|
rowArray.forEach((text, i) => {
|
|
28
28
|
let run: Run = defaultJsonRun;
|
|
29
|
-
if (fieldtype !==
|
|
30
|
-
text = `${striphtml(text.toString(), { cb: replaceBr })}` ||
|
|
31
|
-
}
|
|
32
|
-
run.text = text;
|
|
33
|
-
run.Bold = style.isBold;
|
|
34
|
-
run.Italic = style.IsItalic;
|
|
35
|
-
run.Underline = style.IsUnderline;
|
|
36
|
-
run.Size = style.Size;
|
|
37
|
-
if (run.Uri === "") {
|
|
38
|
-
run.Uri = null;
|
|
39
|
-
} else {
|
|
40
|
-
run.Uri = style.Uri;
|
|
41
|
-
}
|
|
42
|
-
run.Font = style.Font;
|
|
43
|
-
if (rowArray.length == 1) {
|
|
44
|
-
run.InsertLineBreak = style.InsertLineBreak;
|
|
45
|
-
} else {
|
|
46
|
-
run.InsertLineBreak = false;
|
|
29
|
+
if (fieldtype !== 'SuiteHeaderParagraphTitle') {
|
|
30
|
+
text = `${striphtml(text.toString(), { cb: replaceBr })}` || '';
|
|
47
31
|
}
|
|
48
|
-
if (
|
|
49
|
-
run.
|
|
32
|
+
if (run.type === 'text') {
|
|
33
|
+
run.value = text;
|
|
34
|
+
run.textStyling.Bold = style.isBold;
|
|
35
|
+
run.textStyling.Italic = style.IsItalic;
|
|
36
|
+
run.textStyling.Underline = style.IsUnderline;
|
|
37
|
+
run.textStyling.Size = style.Size;
|
|
38
|
+
|
|
39
|
+
if (run.textStyling.Uri === '') {
|
|
40
|
+
run.textStyling.Uri = null;
|
|
41
|
+
} else {
|
|
42
|
+
run.textStyling.Uri = style.Uri;
|
|
43
|
+
}
|
|
44
|
+
run.textStyling.Font = style.Font;
|
|
45
|
+
if (rowArray.length == 1) {
|
|
46
|
+
run.textStyling.InsertLineBreak = style.InsertLineBreak;
|
|
47
|
+
} else {
|
|
48
|
+
run.textStyling.InsertLineBreak = false;
|
|
49
|
+
}
|
|
50
|
+
if (rowArray.length - 1 == i) {
|
|
51
|
+
run.textStyling.InsertLineBreak = style.InsertLineBreak;
|
|
52
|
+
}
|
|
53
|
+
run.textStyling.InsertSpace = style.InsertSpace;
|
|
54
|
+
runs.push(JSON.parse(JSON.stringify(run)));
|
|
50
55
|
}
|
|
51
|
-
run.InsertSpace = style.InsertSpace;
|
|
52
|
-
runs.push(JSON.parse(JSON.stringify(run)));
|
|
53
56
|
});
|
|
54
57
|
} catch (e) {
|
|
55
58
|
logger.silly(`${value} - cannot be splitted`);
|
|
56
59
|
runs[0] = defaultJsonRun;
|
|
57
|
-
|
|
58
|
-
? `${striphtml(value.toString(), { cb: replaceBr })}`
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
if (defaultJsonRun.type === 'text') {
|
|
61
|
+
runs[0].value = value ? `${striphtml(value.toString(), { cb: replaceBr })}` : ``;
|
|
62
|
+
runs[0].textStyling.Bold = style.isBold;
|
|
63
|
+
runs[0].textStyling.Italic = style.IsItalic;
|
|
64
|
+
runs[0].textStyling.Underline = style.IsUnderline;
|
|
65
|
+
runs[0].textStyling.Size = style.Size;
|
|
66
|
+
if (runs[0].textStyling.Uri === '') {
|
|
67
|
+
runs[0].textStyling.Uri = null;
|
|
68
|
+
} else {
|
|
69
|
+
runs[0].textStyling.Uri = style.Uri;
|
|
70
|
+
}
|
|
71
|
+
runs[0].textStyling.Font = style.Font;
|
|
72
|
+
runs[0].textStyling.InsertLineBreak = style.InsertLineBreak;
|
|
73
|
+
runs[0].textStyling.InsertSpace = style.InsertSpace;
|
|
68
74
|
}
|
|
69
|
-
runs[0].Font = style.Font;
|
|
70
|
-
runs[0].InsertLineBreak = style.InsertLineBreak;
|
|
71
|
-
runs[0].InsertSpace = style.InsertSpace;
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
return runs;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { Run, StyleOptions } from
|
|
1
|
+
import { Run, StyleOptions } from './wordJsonModels';
|
|
2
2
|
|
|
3
3
|
export let defaultJsonRun: Run = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
type: 'text',
|
|
5
|
+
value: ``,
|
|
6
|
+
textStyling: {
|
|
7
|
+
Bold: false,
|
|
8
|
+
Italic: false,
|
|
9
|
+
Underline: false,
|
|
10
|
+
Size: 12,
|
|
11
|
+
Uri: null,
|
|
12
|
+
Font: 'Arial',
|
|
13
|
+
InsertLineBreak: false,
|
|
14
|
+
InsertSpace: true,
|
|
15
|
+
},
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
export let DescriptionandProcedureStyle: StyleOptions = {
|
|
@@ -18,7 +21,7 @@ export let DescriptionandProcedureStyle: StyleOptions = {
|
|
|
18
21
|
IsUnderline: true,
|
|
19
22
|
Size: 12,
|
|
20
23
|
Uri: null,
|
|
21
|
-
Font:
|
|
24
|
+
Font: 'Arial',
|
|
22
25
|
InsertLineBreak: false,
|
|
23
26
|
InsertSpace: false,
|
|
24
|
-
};
|
|
27
|
+
};
|
|
@@ -1,71 +1,363 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
Run,
|
|
3
|
+
WIProperty,
|
|
4
|
+
StyleOptions,
|
|
5
|
+
RichNode,
|
|
6
|
+
Paragraph,
|
|
7
|
+
Table,
|
|
8
|
+
TableRow,
|
|
9
|
+
TableCell,
|
|
10
|
+
List,
|
|
11
|
+
ListItem,
|
|
12
|
+
} from '../wordJsonModels';
|
|
6
13
|
|
|
7
14
|
export default class JSONRichTextParagraph {
|
|
8
15
|
paragraphStyles: StyleOptions;
|
|
9
16
|
paragraphTemplate: any;
|
|
10
17
|
wiId: number;
|
|
11
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
field: WIProperty,
|
|
20
|
+
paragraphStyles: StyleOptions,
|
|
21
|
+
wiId: number,
|
|
22
|
+
headingLevel: number,
|
|
23
|
+
skipImageFormat = false
|
|
24
|
+
) {
|
|
12
25
|
this.paragraphStyles = paragraphStyles;
|
|
13
26
|
this.wiId = wiId;
|
|
14
|
-
this.paragraphTemplate = this.
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
this.paragraphTemplate = this.buildDocFromNodes(field.richTextNodes);
|
|
28
|
+
} //constructor
|
|
29
|
+
|
|
30
|
+
getJSONRichTextParagraph(): any[] {
|
|
31
|
+
return this.paragraphTemplate;
|
|
32
|
+
} //getJSONTable
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Parses a given RichNode and returns a corresponding Paragraph, Table, List,
|
|
36
|
+
* an array of these types, or null if the node type is not recognized.
|
|
37
|
+
*
|
|
38
|
+
* @param node - The RichNode to be parsed.
|
|
39
|
+
* @returns A Paragraph, Table, List, an array of these types, or null.
|
|
40
|
+
*
|
|
41
|
+
* The function handles different node types as follows:
|
|
42
|
+
* - 'paragraph': Parses the node as a paragraph.
|
|
43
|
+
* - 'table': Parses the node as a table.
|
|
44
|
+
* - 'list': Parses the node as a list.
|
|
45
|
+
* - 'text', 'image', 'break': Converts the node to a paragraph with a single run.
|
|
46
|
+
* - 'other': Recursively parses child nodes and returns an array of results.
|
|
47
|
+
* - Default: Returns null for unrecognized node types.
|
|
48
|
+
*/
|
|
49
|
+
private parseNode(node: RichNode): Paragraph | Table | List | Array<Paragraph | Table | List> | null {
|
|
50
|
+
switch (node.type) {
|
|
51
|
+
case 'paragraph':
|
|
52
|
+
return this.parseParagraphNode(node);
|
|
53
|
+
case 'table':
|
|
54
|
+
return this.parseTableNode(node);
|
|
55
|
+
case 'list':
|
|
56
|
+
return this.parseList(node);
|
|
57
|
+
case 'text':
|
|
58
|
+
case 'image':
|
|
59
|
+
case 'break':
|
|
60
|
+
return { type: 'paragraph', runs: [this.nodeToRun(node)] };
|
|
61
|
+
case 'other':
|
|
62
|
+
let childrenResults: Array<Paragraph | Table | List> = [];
|
|
63
|
+
for (const child of node.children) {
|
|
64
|
+
const childResult = this.parseNode(child);
|
|
65
|
+
if (Array.isArray(childResult)) {
|
|
66
|
+
childrenResults.push(...childResult);
|
|
67
|
+
} else if (childResult) {
|
|
68
|
+
childrenResults.push(childResult);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return childrenResults.length > 0 ? childrenResults : null;
|
|
72
|
+
default:
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parses a paragraph node and converts it into a Paragraph object.
|
|
79
|
+
*
|
|
80
|
+
* @param node - The node to parse, expected to have a `children` property.
|
|
81
|
+
* @returns A Paragraph object containing the parsed runs.
|
|
82
|
+
*/
|
|
83
|
+
private parseParagraphNode(node: any): Paragraph {
|
|
84
|
+
const runs: Run[] = this.gatherRuns(node.children);
|
|
85
|
+
return { type: 'paragraph', runs };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Gathers runs from the provided children nodes.
|
|
90
|
+
*
|
|
91
|
+
* This method processes an array of child nodes and converts them into an array of `Run` objects.
|
|
92
|
+
* It handles different types of nodes such as text, image, break, paragraph, table, list, and other.
|
|
93
|
+
*
|
|
94
|
+
* - For `text`, `image`, and `break` nodes, it directly converts them to `Run` objects.
|
|
95
|
+
* - For `paragraph` nodes, it recursively gathers runs from the child paragraphs.
|
|
96
|
+
* - For `table` and `list` nodes, it adds a placeholder `Run` object indicating the embedded type.
|
|
97
|
+
* - For `other` nodes, it recursively gathers runs from the child nodes.
|
|
98
|
+
*
|
|
99
|
+
* @param children - An array of child nodes to process.
|
|
100
|
+
* @returns An array of `Run` objects representing the gathered runs.
|
|
101
|
+
*/
|
|
102
|
+
private gatherRuns(children: any[]): Run[] {
|
|
103
|
+
const runs: Run[] = [];
|
|
104
|
+
|
|
105
|
+
for (const child of children || []) {
|
|
106
|
+
if (child.type === 'text' || child.type === 'image' || child.type === 'break') {
|
|
107
|
+
runs.push(this.nodeToRun(child));
|
|
108
|
+
} else if (child.type === 'paragraph') {
|
|
109
|
+
// Recursively gather runs from child paragraphs
|
|
110
|
+
runs.push(...this.gatherRuns(child.children));
|
|
111
|
+
} else if (child.type === 'table' || child.type === 'list') {
|
|
112
|
+
// Not supported in this context, so we'll just add a placeholder
|
|
113
|
+
runs.push({ type: 'other', value: `[Embedded ${child.type}]` });
|
|
114
|
+
} else if (child.type === 'other') {
|
|
115
|
+
// Recursively gather runs from inside <span> or <b>, etc.
|
|
116
|
+
// TODO: Handle b and i, u tags and more relevant tags for text styling
|
|
117
|
+
runs.push(...this.gatherRuns(child.children));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return runs;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Converts a node object to a Run object based on its type and text styling.
|
|
125
|
+
*
|
|
126
|
+
* @param node - The node object to be converted. It can be of type 'text', 'image', or 'break'.
|
|
127
|
+
* @returns A Run object with the appropriate type and properties based on the input node.
|
|
128
|
+
*
|
|
129
|
+
* The Run object can have the following structure:
|
|
130
|
+
* - For 'text' nodes: { type: 'text', value: string, textStyling: object }
|
|
131
|
+
* - For 'image' nodes: { type: 'image', value: '', src: string }
|
|
132
|
+
* - For 'break' nodes: { type: 'break' }
|
|
133
|
+
* - For other types: { type: 'other', value: '' }
|
|
134
|
+
*
|
|
135
|
+
* The textStyling object includes:
|
|
136
|
+
* - Bold: boolean
|
|
137
|
+
* - Italic: boolean
|
|
138
|
+
* - Underline: boolean
|
|
139
|
+
* - Size: number
|
|
140
|
+
* - Uri: string | null
|
|
141
|
+
* - Font: string
|
|
142
|
+
* - InsertLineBreak: boolean
|
|
143
|
+
* - InsertSpace: boolean
|
|
144
|
+
*/
|
|
145
|
+
private nodeToRun(node: any): Run {
|
|
146
|
+
const textStyling = {
|
|
147
|
+
Bold: node.textStyling?.Bold || this.paragraphStyles.isBold,
|
|
148
|
+
Italic: node.textStyling?.Italic || this.paragraphStyles.IsItalic,
|
|
149
|
+
Underline: node.textStyling?.Underline || this.paragraphStyles.IsUnderline,
|
|
150
|
+
Size: this.paragraphStyles.Size || 12,
|
|
151
|
+
Uri: this.paragraphStyles.Uri || null,
|
|
152
|
+
Font: this.paragraphStyles.Font || 'Arial',
|
|
153
|
+
InsertLineBreak: this.paragraphStyles.InsertLineBreak || false,
|
|
154
|
+
InsertSpace: node.textStyling?.InsertSpace || this.paragraphStyles.InsertSpace,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
if (node.type === 'text') {
|
|
158
|
+
return { type: 'text', value: node.value, textStyling: textStyling };
|
|
159
|
+
} else if (node.type === 'image') {
|
|
160
|
+
return { type: 'image', value: '', src: node.src || '' };
|
|
161
|
+
} else if (node.type === 'break') {
|
|
162
|
+
return { type: 'break' };
|
|
17
163
|
} else {
|
|
18
|
-
|
|
164
|
+
return { type: 'other', value: '' };
|
|
19
165
|
}
|
|
20
|
-
}
|
|
166
|
+
}
|
|
21
167
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Converts a given node object into a Table structure.
|
|
170
|
+
*
|
|
171
|
+
* @remarks
|
|
172
|
+
* This function processes the children of the specified node and
|
|
173
|
+
* transforms them into a table representation, adding default properties
|
|
174
|
+
* such as heading level, page break insertion, and an empty rows array.
|
|
175
|
+
*
|
|
176
|
+
* @param node - The node object containing the structural details needed
|
|
177
|
+
* to create a table.
|
|
178
|
+
* @returns A fully constructed Table object with the parsed node data.
|
|
179
|
+
*/
|
|
180
|
+
private parseTableNode(node: any): Table {
|
|
181
|
+
const table: Table = {
|
|
182
|
+
type: 'table',
|
|
183
|
+
headingLevel: 0,
|
|
184
|
+
insertPageBreak: false,
|
|
185
|
+
Rows: [],
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
this.parseTableChildren(node.children, table);
|
|
189
|
+
return table;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Parses child elements of a table structure and updates the provided Table instance accordingly.
|
|
194
|
+
*
|
|
195
|
+
* @param children - An array of child nodes to be evaluated for table content.
|
|
196
|
+
* @param table - The Table object to which parsed rows and nested structures will be appended.
|
|
197
|
+
*
|
|
198
|
+
* @remarks
|
|
199
|
+
* This method recursively traverses and identifies relevant table elements (e.g., <tr>, <thead>, <tbody>, etc.)
|
|
200
|
+
* to generate the final row data for the given Table instance.
|
|
201
|
+
*/
|
|
202
|
+
private parseTableChildren(children: any[], table: Table): void {
|
|
203
|
+
for (const child of children || []) {
|
|
204
|
+
if (child.type === 'other') {
|
|
205
|
+
const tn = (child.tagName || '').toLowerCase();
|
|
206
|
+
if (tn === 'tr') {
|
|
207
|
+
// Parse a table row
|
|
208
|
+
const row = this.parseTableRow(child);
|
|
209
|
+
table.Rows.push(row);
|
|
210
|
+
} else if (tn === 'thead' || tn === 'tbody' || tn === 'tfoot') {
|
|
211
|
+
// Recurse into thead/tbody/tfoot
|
|
212
|
+
this.parseTableChildren(child.children, table);
|
|
213
|
+
} else {
|
|
214
|
+
// Recurse into other nodes
|
|
215
|
+
this.parseTableChildren(child.children, table);
|
|
59
216
|
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
217
|
+
} else if (child.type === 'table') {
|
|
218
|
+
this.parseTableChildren(child.children, table);
|
|
219
|
+
} else {
|
|
220
|
+
//skip
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
65
223
|
}
|
|
66
|
-
}
|
|
224
|
+
}
|
|
67
225
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Parses the given table row node and extracts its cells by iterating through its child elements.
|
|
228
|
+
* Each child element that is recognized as a table cell (td or th) is converted into a corresponding cell object.
|
|
229
|
+
*
|
|
230
|
+
* @param trNode - An AST node representing the table row, containing possible table cell or header elements.
|
|
231
|
+
* @returns A TableRow object containing an array of processed cells.
|
|
232
|
+
*/
|
|
233
|
+
private parseTableRow(trNode: any): TableRow {
|
|
234
|
+
const row: TableRow = { Cells: [] };
|
|
235
|
+
|
|
236
|
+
// parse <td> or <th> inside this <tr>
|
|
237
|
+
for (const child of trNode.children || []) {
|
|
238
|
+
if (child.type === 'other' && (child.tagName === 'td' || child.tagName === 'th')) {
|
|
239
|
+
row.Cells.push(this.parseTableCell(child));
|
|
240
|
+
} else {
|
|
241
|
+
// skip or recurse
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return row;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Build one TableCell from <td> node
|
|
250
|
+
*/
|
|
251
|
+
private parseTableCell(tdNode: any): TableCell {
|
|
252
|
+
// We'll collect everything in one paragraph
|
|
253
|
+
const cellParagraphRuns = this.gatherRunsFromAllParagraphs(tdNode.children);
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
Paragraphs: [
|
|
257
|
+
{
|
|
258
|
+
Runs: cellParagraphRuns,
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Gather runs from any text/image/paragraph in <td>
|
|
266
|
+
* (including nested <other> tags).
|
|
267
|
+
*/
|
|
268
|
+
private gatherRunsFromAllParagraphs(children: any[]): Run[] {
|
|
269
|
+
const runs: Run[] = [];
|
|
270
|
+
for (const child of children || []) {
|
|
271
|
+
if (child.type === 'text' || child.type === 'image') {
|
|
272
|
+
runs.push(this.nodeToRun(child));
|
|
273
|
+
} else if (child.type === 'paragraph') {
|
|
274
|
+
runs.push(...this.gatherRuns(child.children));
|
|
275
|
+
} else if (child.type === 'other' || child.type === 'table' || child.type === 'list') {
|
|
276
|
+
// recursively gather
|
|
277
|
+
runs.push(...this.gatherRunsFromAllParagraphs(child.children));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return runs;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Parses a given node to create a List object.
|
|
285
|
+
*
|
|
286
|
+
* @param node - The node to parse, expected to have properties `isOrdered` and `children`.
|
|
287
|
+
* @returns A List object with the parsed data.
|
|
288
|
+
*/
|
|
289
|
+
private parseList(node: any): List {
|
|
290
|
+
const list: List = {
|
|
291
|
+
type: 'list',
|
|
292
|
+
isOrdered: node.isOrdered,
|
|
293
|
+
listItems: [],
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
this.parseListChildren(node.children, list);
|
|
297
|
+
return list;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Parses the children of a list and adds them to the provided list object.
|
|
302
|
+
*
|
|
303
|
+
* @param children - An array of child nodes to be parsed.
|
|
304
|
+
* @param list - The list object to which parsed items will be added.
|
|
305
|
+
* @param level - The current depth level of the list (default is 0).
|
|
306
|
+
*/
|
|
307
|
+
private parseListChildren(children: any[], list: List, level: number = 0): void {
|
|
308
|
+
for (const child of children || []) {
|
|
309
|
+
if (child.type === 'other') {
|
|
310
|
+
const tn = (child.tagName || '').toLowerCase();
|
|
311
|
+
if (tn === 'li') {
|
|
312
|
+
// Parse a list item
|
|
313
|
+
const item = this.parseListItem(child, level);
|
|
314
|
+
list.listItems.push(item);
|
|
315
|
+
} else {
|
|
316
|
+
// Recurse into other nodes
|
|
317
|
+
this.parseListChildren(child.children, list, level + 1);
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
//skip
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Parses a list item node and converts it into a `ListItem` object.
|
|
328
|
+
*
|
|
329
|
+
* @param liNode - The list item node to parse.
|
|
330
|
+
* @param level - The nesting level of the list item.
|
|
331
|
+
* @returns A `ListItem` object containing the parsed list item data.
|
|
332
|
+
*/
|
|
333
|
+
private parseListItem(liNode: any, level: number): ListItem {
|
|
334
|
+
const items = this.gatherRunsFromAllParagraphs(liNode.children);
|
|
335
|
+
|
|
336
|
+
return {
|
|
337
|
+
Runs: items,
|
|
338
|
+
level: level,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Builds an array of document elements (Paragraph, Table, or List) from an array of RichNode objects.
|
|
344
|
+
*
|
|
345
|
+
* @param nodes - An array of RichNode objects to be parsed into document elements.
|
|
346
|
+
* @returns An array of Paragraph, Table, or List elements.
|
|
347
|
+
*/
|
|
348
|
+
private buildDocFromNodes(nodes: RichNode[]): Array<Paragraph | Table | List> {
|
|
349
|
+
const results: Array<Paragraph | Table | List> = [];
|
|
350
|
+
|
|
351
|
+
for (const node of nodes) {
|
|
352
|
+
const items = this.parseNode(node);
|
|
353
|
+
// parseNode might return a single Paragraph/Table or an array
|
|
354
|
+
if (Array.isArray(items)) {
|
|
355
|
+
results.push(...items);
|
|
356
|
+
} else if (items) {
|
|
357
|
+
results.push(items);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return results;
|
|
362
|
+
}
|
|
71
363
|
} //class
|
|
@@ -55,8 +55,8 @@ export interface Attachment {
|
|
|
55
55
|
isLinkedFile?: boolean;
|
|
56
56
|
IsFlattened?: boolean;
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
|
|
59
|
+
interface TextStyle {
|
|
60
60
|
Bold: boolean;
|
|
61
61
|
Italic: boolean;
|
|
62
62
|
Underline: boolean;
|
|
@@ -66,6 +66,13 @@ export interface Run {
|
|
|
66
66
|
InsertLineBreak: boolean;
|
|
67
67
|
InsertSpace: boolean;
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
export interface Run {
|
|
71
|
+
type: 'text' | 'image' | 'break' | 'other';
|
|
72
|
+
value?: string;
|
|
73
|
+
src?: string; // If type = 'image', you can store the URL or local path here
|
|
74
|
+
textStyling?: TextStyle; // If type = 'text', store style; if type = 'image', optional or partial
|
|
75
|
+
}
|
|
69
76
|
export interface WorkItemData {}
|
|
70
77
|
|
|
71
78
|
export interface Table {
|
|
@@ -74,6 +81,18 @@ export interface Table {
|
|
|
74
81
|
Rows: TableRow[];
|
|
75
82
|
insertPageBreak: boolean;
|
|
76
83
|
}
|
|
84
|
+
|
|
85
|
+
export interface List {
|
|
86
|
+
type: string;
|
|
87
|
+
listItems: ListItem[];
|
|
88
|
+
isOrdered: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ListItem {
|
|
92
|
+
Runs: Run[];
|
|
93
|
+
level: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
export interface WIQueryResults {
|
|
78
97
|
columns: WIColumns[];
|
|
79
98
|
workItems: WIData[];
|
|
@@ -97,7 +116,7 @@ export interface WIProperty {
|
|
|
97
116
|
attachmentLink?: string;
|
|
98
117
|
attachmentType?: string;
|
|
99
118
|
relativeAttachmentLink?: string;
|
|
100
|
-
|
|
119
|
+
richTextNodes?: any[];
|
|
101
120
|
}
|
|
102
121
|
export interface MultipeValuesWIProperty {
|
|
103
122
|
name: string;
|
|
@@ -109,10 +128,49 @@ export interface MultipeValuesWIProperty {
|
|
|
109
128
|
attachmentLink?: string;
|
|
110
129
|
attachmentType?: string;
|
|
111
130
|
relativeAttachmentLink?: string;
|
|
112
|
-
|
|
131
|
+
richTextNodes?: any[];
|
|
113
132
|
}
|
|
114
133
|
export interface WIColumns {
|
|
115
134
|
name: string;
|
|
116
135
|
referenceName: string;
|
|
117
136
|
url: string;
|
|
118
137
|
}
|
|
138
|
+
|
|
139
|
+
export type RichNode = ParagraphNode | TextNode | ImageNode | TableNode | ListNode | BreakNode | OtherNode;
|
|
140
|
+
|
|
141
|
+
export interface ParagraphNode {
|
|
142
|
+
type: 'paragraph';
|
|
143
|
+
children: RichNode[];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface TextNode {
|
|
147
|
+
type: 'text';
|
|
148
|
+
value: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface ImageNode {
|
|
152
|
+
type: 'image';
|
|
153
|
+
src: string;
|
|
154
|
+
alt?: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface BreakNode {
|
|
158
|
+
type: 'break';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface TableNode {
|
|
162
|
+
type: 'table';
|
|
163
|
+
children: RichNode[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ListNode {
|
|
167
|
+
type: 'list';
|
|
168
|
+
isOrdered: boolean;
|
|
169
|
+
children: RichNode[];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface OtherNode {
|
|
173
|
+
type: 'other';
|
|
174
|
+
tagName: string;
|
|
175
|
+
children: RichNode[];
|
|
176
|
+
}
|