@elisra-devops/docgen-skins 0.10.7 → 0.10.8

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.
@@ -1,16 +1,8 @@
1
+ import { Run, WIProperty, StyleOptions } from '../wordJsonModels';
2
+ import JSONHtml from '../html/JSONHtml';
3
+ import JSONParagraph from './JSONParagraph';
4
+ import JSONTable from '../table/JSONTable';
1
5
  import logger from '../../../services/logger';
2
- import {
3
- Run,
4
- WIProperty,
5
- StyleOptions,
6
- RichNode,
7
- Paragraph,
8
- Table,
9
- TableRow,
10
- TableCell,
11
- List,
12
- ListItem,
13
- } from '../wordJsonModels';
14
6
 
15
7
  export default class JSONRichTextParagraph {
16
8
  paragraphStyles: StyleOptions;
@@ -25,355 +17,411 @@ export default class JSONRichTextParagraph {
25
17
  ) {
26
18
  this.paragraphStyles = paragraphStyles;
27
19
  this.wiId = wiId;
28
- this.paragraphTemplate = this.buildDocFromNodes(field.richTextNodes);
20
+ this.paragraphTemplate = this.generateJsonRichTextParagraphs(
21
+ field,
22
+ this.paragraphStyles,
23
+ skipImageFormat
24
+ );
25
+ if (headingLevel && field.name === 'Title: ') {
26
+ this.paragraphTemplate.headingLevel = headingLevel;
27
+ }
29
28
  } //constructor
30
29
 
31
- getJSONRichTextParagraph(): any[] {
32
- return this.paragraphTemplate;
33
- } //getJSONTable
30
+ generateJsonRichTextParagraphs(field: WIProperty, paragraphStyles, skipImageFormat = false): Run[] {
31
+ let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
34
32
 
35
- /**
36
- * Parses a given RichNode and returns a corresponding Paragraph, Table, List,
37
- * an array of these types, or null if the node type is not recognized.
38
- *
39
- * @param node - The RichNode to be parsed.
40
- * @returns A Paragraph, Table, List, an array of these types, or null.
41
- *
42
- * The function handles different node types as follows:
43
- * - 'paragraph': Parses the node as a paragraph.
44
- * - 'table': Parses the node as a table.
45
- * - 'list': Parses the node as a list.
46
- * - 'text', 'image', 'break': Converts the node to a paragraph with a single run.
47
- * - 'other': Recursively parses child nodes and returns an array of results.
48
- * - Default: Returns null for unrecognized node types.
49
- */
50
- private parseNode(node: RichNode): Paragraph | Table | List | Array<Paragraph | Table | List> | null {
51
- if (!node || typeof node.type !== 'string') {
52
- logger.warn(`Invalid node structure: ${JSON.stringify(node)}`);
53
- return null;
54
- }
33
+ titleStyle.isBold = true;
34
+ titleStyle.IsUnderline = true;
35
+ titleStyle.InsertSpace = true;
36
+ titleStyle.InsertLineBreak = false;
37
+
38
+ let richTextSkin: any[] = [];
39
+ //handle rich text
40
+ try {
41
+ field.richText.forEach((content) => {
42
+ switch (content.type) {
43
+ case 'paragraph':
44
+ content.data.fields.forEach((richTextField: WIProperty) => {
45
+ if (/<\/?[a-z][\s\S]*>/.test(richTextField.value)) {
46
+ let html = new JSONHtml(richTextField.value);
47
+ richTextSkin.push(html.getJSONHtml());
48
+ } else {
49
+ //making sure ID is not printed
50
+ let paragraphSkin = new JSONParagraph(richTextField, paragraphStyles, 0, 0);
51
+ richTextSkin.push(paragraphSkin.getJSONParagraph());
52
+ }
53
+ });
54
+ break;
55
+ case 'picture':
56
+ if (!skipImageFormat) {
57
+ richTextSkin.push({
58
+ type: 'picture',
59
+ Path: content.data,
60
+ });
61
+ }
55
62
 
56
- switch (node.type) {
57
- case 'paragraph':
58
- return this.parseParagraphNode(node);
59
- case 'table':
60
- return this.parseTableNode(node);
61
- case 'list':
62
- return this.parseList(node);
63
- case 'text':
64
- case 'image':
65
- case 'break':
66
- return { type: 'paragraph', runs: [this.nodeToRun(node)] };
67
- case 'other':
68
- let childrenResults: Array<Paragraph | Table | List> = [];
69
- for (const child of node.children) {
70
- const childResult = this.parseNode(child);
71
- if (Array.isArray(childResult)) {
72
- childrenResults.push(...childResult);
73
- } else if (childResult) {
74
- childrenResults.push(childResult);
75
- }
63
+ break;
64
+ case 'table':
65
+ if (content.data) {
66
+ let tableSkin = new JSONTable(content.data, undefined, paragraphStyles, 0);
67
+ richTextSkin.push(tableSkin.getJSONTable());
68
+ }
69
+ break;
76
70
  }
77
- return childrenResults.length > 0 ? childrenResults : null;
78
- default:
79
- return null;
71
+ });
72
+ return richTextSkin;
73
+ } catch (e) {
74
+ logger.warn(e);
75
+ return [];
80
76
  }
81
- }
77
+ } //generateJsonRichTextParagraphs
82
78
 
83
- /**
84
- * Parses a paragraph node and converts it into a Paragraph object.
85
- *
86
- * @param node - The node to parse, expected to have a `children` property.
87
- * @returns A Paragraph object containing the parsed runs.
88
- */
89
- private parseParagraphNode(node: any): Paragraph {
90
- const runs: Run[] = this.gatherRuns(node.children);
91
- return { type: 'paragraph', runs };
92
- }
79
+ getJSONRichTextParagraph(): any[] {
80
+ return this.paragraphTemplate;
81
+ } //getJSONRichTextParagraph
93
82
 
94
- /**
95
- * Gathers runs from the provided children nodes.
96
- *
97
- * This method processes an array of child nodes and converts them into an array of `Run` objects.
98
- * It handles different types of nodes such as text, image, break, paragraph, table, list, and other.
99
- *
100
- * - For `text`, `image`, and `break` nodes, it directly converts them to `Run` objects.
101
- * - For `paragraph` nodes, it recursively gathers runs from the child paragraphs.
102
- * - For `table` and `list` nodes, it adds a placeholder `Run` object indicating the embedded type.
103
- * - For `other` nodes, it recursively gathers runs from the child nodes.
104
- *
105
- * @param children - An array of child nodes to process.
106
- * @returns An array of `Run` objects representing the gathered runs.
107
- */
108
- private gatherRuns(children: any[]): Run[] {
109
- const runs: Run[] = [];
110
- if (!Array.isArray(children)) {
111
- logger.warn(`Invalid children structure: ${JSON.stringify(children)}`);
112
- return runs;
113
- }
114
- for (const child of children || []) {
115
- if (child.type === 'text' || child.type === 'image' || child.type === 'break') {
116
- runs.push(this.nodeToRun(child));
117
- } else if (child.type === 'paragraph') {
118
- // Recursively gather runs from child paragraphs
119
- runs.push(...this.gatherRuns(child.children));
120
- } else if (child.type === 'table' || child.type === 'list') {
121
- // Not supported in this context, so we'll just add a placeholder
122
- runs.push({ type: 'other', value: `[Embedded ${child.type}]` });
123
- } else if (child.type === 'other') {
124
- // Recursively gather runs from inside <span> or <b>, etc.
125
- // TODO: Handle b and i, u tags and more relevant tags for text styling
126
- runs.push(...this.gatherRuns(child.children));
127
- }
128
- }
129
- return runs;
130
- }
83
+ // /**
84
+ // * Parses a given RichNode and returns a corresponding Paragraph, Table, List,
85
+ // * an array of these types, or null if the node type is not recognized.
86
+ // *
87
+ // * @param node - The RichNode to be parsed.
88
+ // * @returns A Paragraph, Table, List, an array of these types, or null.
89
+ // *
90
+ // * The function handles different node types as follows:
91
+ // * - 'paragraph': Parses the node as a paragraph.
92
+ // * - 'table': Parses the node as a table.
93
+ // * - 'list': Parses the node as a list.
94
+ // * - 'text', 'image', 'break': Converts the node to a paragraph with a single run.
95
+ // * - 'other': Recursively parses child nodes and returns an array of results.
96
+ // * - Default: Returns null for unrecognized node types.
97
+ // */
98
+ // private parseNode(node: RichNode): Paragraph | Table | List | Array<Paragraph | Table | List> | null {
99
+ // if (!node || typeof node.type !== 'string') {
100
+ // logger.warn(`Invalid node structure: ${JSON.stringify(node)}`);
101
+ // return null;
102
+ // }
131
103
 
132
- /**
133
- * Converts a node object to a Run object based on its type and text styling.
134
- *
135
- * @param node - The node object to be converted. It can be of type 'text', 'image', or 'break'.
136
- * @returns A Run object with the appropriate type and properties based on the input node.
137
- *
138
- * The Run object can have the following structure:
139
- * - For 'text' nodes: { type: 'text', value: string, textStyling: object }
140
- * - For 'image' nodes: { type: 'image', value: '', src: string }
141
- * - For 'break' nodes: { type: 'break' }
142
- * - For other types: { type: 'other', value: '' }
143
- *
144
- * The textStyling object includes:
145
- * - Bold: boolean
146
- * - Italic: boolean
147
- * - Underline: boolean
148
- * - Size: number
149
- * - Uri: string | null
150
- * - Font: string
151
- * - InsertLineBreak: boolean
152
- * - InsertSpace: boolean
153
- */
154
- private nodeToRun(node: any): Run {
155
- const textStyling = {
156
- ...this.paragraphStyles, // Base styles
157
- ...node.textStyling, // Override with node specific styling
158
- Size: this.paragraphStyles.Size || 12,
159
- Uri: this.paragraphStyles.Uri || null,
160
- Font: this.paragraphStyles.Font || 'Arial',
161
- InsertLineBreak: this.paragraphStyles.InsertLineBreak || false,
162
- };
104
+ // switch (node.type) {
105
+ // case 'paragraph':
106
+ // return this.parseParagraphNode(node);
107
+ // case 'table':
108
+ // return this.parseTableNode(node);
109
+ // case 'list':
110
+ // return this.parseList(node);
111
+ // case 'text':
112
+ // case 'image':
113
+ // case 'break':
114
+ // return { type: 'paragraph', runs: [this.nodeToRun(node)] };
115
+ // case 'other':
116
+ // let childrenResults: Array<Paragraph | Table | List> = [];
117
+ // for (const child of node.children) {
118
+ // const childResult = this.parseNode(child);
119
+ // if (Array.isArray(childResult)) {
120
+ // childrenResults.push(...childResult);
121
+ // } else if (childResult) {
122
+ // childrenResults.push(childResult);
123
+ // }
124
+ // }
125
+ // return childrenResults.length > 0 ? childrenResults : null;
126
+ // default:
127
+ // return null;
128
+ // }
129
+ // }
163
130
 
164
- if (node.type === 'text') {
165
- return { type: 'text', value: node.value, textStyling: textStyling };
166
- } else if (node.type === 'image') {
167
- return { type: 'image', value: '', src: node.src || '' };
168
- } else if (node.type === 'break') {
169
- return { type: 'break' };
170
- } else {
171
- return { type: 'other', value: '' };
172
- }
173
- }
131
+ // /**
132
+ // * Parses a paragraph node and converts it into a Paragraph object.
133
+ // *
134
+ // * @param node - The node to parse, expected to have a `children` property.
135
+ // * @returns A Paragraph object containing the parsed runs.
136
+ // */
137
+ // private parseParagraphNode(node: any): Paragraph {
138
+ // const runs: Run[] = this.gatherRuns(node.children);
139
+ // return { type: 'paragraph', runs };
140
+ // }
174
141
 
175
- /**
176
- * Converts a given node object into a Table structure.
177
- *
178
- * @remarks
179
- * This function processes the children of the specified node and
180
- * transforms them into a table representation, adding default properties
181
- * such as heading level, page break insertion, and an empty rows array.
182
- *
183
- * @param node - The node object containing the structural details needed
184
- * to create a table.
185
- * @returns A fully constructed Table object with the parsed node data.
186
- */
187
- private parseTableNode(node: any): Table {
188
- const table: Table = {
189
- type: 'table',
190
- headingLevel: 0,
191
- insertPageBreak: false,
192
- Rows: [],
193
- };
142
+ // /**
143
+ // * Gathers runs from the provided children nodes.
144
+ // *
145
+ // * This method processes an array of child nodes and converts them into an array of `Run` objects.
146
+ // * It handles different types of nodes such as text, image, break, paragraph, table, list, and other.
147
+ // *
148
+ // * - For `text`, `image`, and `break` nodes, it directly converts them to `Run` objects.
149
+ // * - For `paragraph` nodes, it recursively gathers runs from the child paragraphs.
150
+ // * - For `table` and `list` nodes, it adds a placeholder `Run` object indicating the embedded type.
151
+ // * - For `other` nodes, it recursively gathers runs from the child nodes.
152
+ // *
153
+ // * @param children - An array of child nodes to process.
154
+ // * @returns An array of `Run` objects representing the gathered runs.
155
+ // */
156
+ // private gatherRuns(children: any[]): Run[] {
157
+ // const runs: Run[] = [];
158
+ // if (!Array.isArray(children)) {
159
+ // logger.warn(`Invalid children structure: ${JSON.stringify(children)}`);
160
+ // return runs;
161
+ // }
162
+ // for (const child of children || []) {
163
+ // if (child.type === 'text' || child.type === 'image' || child.type === 'break') {
164
+ // runs.push(this.nodeToRun(child));
165
+ // } else if (child.type === 'paragraph') {
166
+ // // Recursively gather runs from child paragraphs
167
+ // runs.push(...this.gatherRuns(child.children));
168
+ // } else if (child.type === 'table' || child.type === 'list') {
169
+ // // Not supported in this context, so we'll just add a placeholder
170
+ // runs.push({ type: 'other', value: `[Embedded ${child.type}]` });
171
+ // } else if (child.type === 'other') {
172
+ // // Recursively gather runs from inside <span> or <b>, etc.
173
+ // // TODO: Handle b and i, u tags and more relevant tags for text styling
174
+ // runs.push(...this.gatherRuns(child.children));
175
+ // }
176
+ // }
177
+ // return runs;
178
+ // }
194
179
 
195
- this.parseTableChildren(node.children, table);
196
- return table;
197
- }
180
+ // /**
181
+ // * Converts a node object to a Run object based on its type and text styling.
182
+ // *
183
+ // * @param node - The node object to be converted. It can be of type 'text', 'image', or 'break'.
184
+ // * @returns A Run object with the appropriate type and properties based on the input node.
185
+ // *
186
+ // * The Run object can have the following structure:
187
+ // * - For 'text' nodes: { type: 'text', value: string, textStyling: object }
188
+ // * - For 'image' nodes: { type: 'image', value: '', src: string }
189
+ // * - For 'break' nodes: { type: 'break' }
190
+ // * - For other types: { type: 'other', value: '' }
191
+ // *
192
+ // * The textStyling object includes:
193
+ // * - Bold: boolean
194
+ // * - Italic: boolean
195
+ // * - Underline: boolean
196
+ // * - Size: number
197
+ // * - Uri: string | null
198
+ // * - Font: string
199
+ // * - InsertLineBreak: boolean
200
+ // * - InsertSpace: boolean
201
+ // */
202
+ // private nodeToRun(node: any): Run {
203
+ // const textStyling = {
204
+ // ...this.paragraphStyles, // Base styles
205
+ // ...node.textStyling, // Override with node specific styling
206
+ // Size: this.paragraphStyles.Size || 12,
207
+ // Uri: this.paragraphStyles.Uri || null,
208
+ // Font: this.paragraphStyles.Font || 'Arial',
209
+ // InsertLineBreak: this.paragraphStyles.InsertLineBreak || false,
210
+ // };
198
211
 
199
- /**
200
- * Parses child elements of a table structure and updates the provided Table instance accordingly.
201
- *
202
- * @param children - An array of child nodes to be evaluated for table content.
203
- * @param table - The Table object to which parsed rows and nested structures will be appended.
204
- *
205
- * @remarks
206
- * This method recursively traverses and identifies relevant table elements (e.g., <tr>, <thead>, <tbody>, etc.)
207
- * to generate the final row data for the given Table instance.
208
- */
209
- private parseTableChildren(children: any[], table: Table): void {
210
- for (const child of children || []) {
211
- if (child.type === 'other') {
212
- const tn = (child.tagName || '').toLowerCase();
213
- if (tn === 'tr') {
214
- // Parse a table row
215
- const row = this.parseTableRow(child);
216
- table.Rows.push(row);
217
- } else if (tn === 'thead' || tn === 'tbody' || tn === 'tfoot') {
218
- // Recurse into thead/tbody/tfoot
219
- this.parseTableChildren(child.children, table);
220
- } else {
221
- // Recurse into other nodes
222
- this.parseTableChildren(child.children, table);
223
- }
224
- } else if (child.type === 'table') {
225
- this.parseTableChildren(child.children, table);
226
- } else {
227
- //skip
228
- continue;
229
- }
230
- }
231
- }
212
+ // if (node.type === 'text') {
213
+ // return { type: 'text', value: node.value, textStyling: textStyling };
214
+ // } else if (node.type === 'image') {
215
+ // return { type: 'image', value: '', src: node.src || '' };
216
+ // } else if (node.type === 'break') {
217
+ // return { type: 'break' };
218
+ // } else {
219
+ // return { type: 'other', value: '' };
220
+ // }
221
+ // }
232
222
 
233
- /**
234
- * Parses the given table row node and extracts its cells by iterating through its child elements.
235
- * Each child element that is recognized as a table cell (td or th) is converted into a corresponding cell object.
236
- *
237
- * @param trNode - An AST node representing the table row, containing possible table cell or header elements.
238
- * @returns A TableRow object containing an array of processed cells.
239
- */
240
- private parseTableRow(trNode: any): TableRow {
241
- const row: TableRow = { Cells: [] };
223
+ // /**
224
+ // * Converts a given node object into a Table structure.
225
+ // *
226
+ // * @remarks
227
+ // * This function processes the children of the specified node and
228
+ // * transforms them into a table representation, adding default properties
229
+ // * such as heading level, page break insertion, and an empty rows array.
230
+ // *
231
+ // * @param node - The node object containing the structural details needed
232
+ // * to create a table.
233
+ // * @returns A fully constructed Table object with the parsed node data.
234
+ // */
235
+ // private parseTableNode(node: any): Table {
236
+ // const table: Table = {
237
+ // type: 'table',
238
+ // headingLevel: 0,
239
+ // insertPageBreak: false,
240
+ // Rows: [],
241
+ // };
242
242
 
243
- // parse <td> or <th> inside this <tr>
244
- for (const child of trNode.children || []) {
245
- if (child.type === 'other' && (child.tagName === 'td' || child.tagName === 'th')) {
246
- row.Cells.push(this.parseTableCell(child));
247
- } else {
248
- // skip or recurse
249
- }
250
- }
243
+ // this.parseTableChildren(node.children, table);
244
+ // return table;
245
+ // }
251
246
 
252
- return row;
253
- }
247
+ // /**
248
+ // * Parses child elements of a table structure and updates the provided Table instance accordingly.
249
+ // *
250
+ // * @param children - An array of child nodes to be evaluated for table content.
251
+ // * @param table - The Table object to which parsed rows and nested structures will be appended.
252
+ // *
253
+ // * @remarks
254
+ // * This method recursively traverses and identifies relevant table elements (e.g., <tr>, <thead>, <tbody>, etc.)
255
+ // * to generate the final row data for the given Table instance.
256
+ // */
257
+ // private parseTableChildren(children: any[], table: Table): void {
258
+ // for (const child of children || []) {
259
+ // if (child.type === 'other') {
260
+ // const tn = (child.tagName || '').toLowerCase();
261
+ // if (tn === 'tr') {
262
+ // // Parse a table row
263
+ // const row = this.parseTableRow(child);
264
+ // table.Rows.push(row);
265
+ // } else if (tn === 'thead' || tn === 'tbody' || tn === 'tfoot') {
266
+ // // Recurse into thead/tbody/tfoot
267
+ // this.parseTableChildren(child.children, table);
268
+ // } else {
269
+ // // Recurse into other nodes
270
+ // this.parseTableChildren(child.children, table);
271
+ // }
272
+ // } else if (child.type === 'table') {
273
+ // this.parseTableChildren(child.children, table);
274
+ // } else {
275
+ // //skip
276
+ // continue;
277
+ // }
278
+ // }
279
+ // }
254
280
 
255
- /**
256
- * Build one TableCell from <td> node
257
- */
258
- private parseTableCell(tdNode: any): TableCell {
259
- // We'll collect everything in one paragraph
260
- const cellParagraphRuns = this.gatherRunsFromAllParagraphs(tdNode.children);
281
+ // /**
282
+ // * Parses the given table row node and extracts its cells by iterating through its child elements.
283
+ // * Each child element that is recognized as a table cell (td or th) is converted into a corresponding cell object.
284
+ // *
285
+ // * @param trNode - An AST node representing the table row, containing possible table cell or header elements.
286
+ // * @returns A TableRow object containing an array of processed cells.
287
+ // */
288
+ // private parseTableRow(trNode: any): TableRow {
289
+ // const row: TableRow = { Cells: [] };
261
290
 
262
- return {
263
- Paragraphs: [
264
- {
265
- Runs: cellParagraphRuns,
266
- },
267
- ],
268
- };
269
- }
291
+ // // parse <td> or <th> inside this <tr>
292
+ // for (const child of trNode.children || []) {
293
+ // if (child.type === 'other' && (child.tagName === 'td' || child.tagName === 'th')) {
294
+ // row.Cells.push(this.parseTableCell(child));
295
+ // } else {
296
+ // // skip or recurse
297
+ // }
298
+ // }
270
299
 
271
- /**
272
- * Gather runs from any text/image/paragraph in <td>
273
- * (including nested <other> tags).
274
- */
275
- private gatherRunsFromAllParagraphs(children: any[]): Run[] {
276
- const runs: Run[] = [];
277
- for (const child of children || []) {
278
- if (child.type === 'text' || child.type === 'image') {
279
- runs.push(this.nodeToRun(child));
280
- } else if (child.type === 'paragraph') {
281
- runs.push(...this.gatherRuns(child.children));
282
- } else if (child.type === 'other' || child.type === 'table' || child.type === 'list') {
283
- // recursively gather
284
- runs.push(...this.gatherRunsFromAllParagraphs(child.children));
285
- }
286
- }
287
- return runs;
288
- }
300
+ // return row;
301
+ // }
289
302
 
290
- /**
291
- * Parses a given node to create a List object.
292
- *
293
- * @param node - The node to parse, expected to have properties `isOrdered` and `children`.
294
- * @returns A List object with the parsed data.
295
- */
296
- private parseList(node: any): List {
297
- const list: List = {
298
- type: 'list',
299
- isOrdered: node.isOrdered,
300
- listItems: [],
301
- };
303
+ // /**
304
+ // * Build one TableCell from <td> node
305
+ // */
306
+ // private parseTableCell(tdNode: any): TableCell {
307
+ // // We'll collect everything in one paragraph
308
+ // const cellParagraphRuns = this.gatherRunsFromAllParagraphs(tdNode.children);
302
309
 
303
- this.parseListChildren(node.children, list);
304
- return list;
305
- }
310
+ // return {
311
+ // Paragraphs: [
312
+ // {
313
+ // Runs: cellParagraphRuns,
314
+ // },
315
+ // ],
316
+ // };
317
+ // }
306
318
 
307
- /**
308
- * Parses the children of a list and adds them to the provided list object.
309
- *
310
- * @param children - An array of child nodes to be parsed.
311
- * @param list - The list object to which parsed items will be added.
312
- * @param level - The current depth level of the list (default is 0).
313
- */
314
- private parseListChildren(children: any[], list: List, level: number = 0): void {
315
- if (level > 10) {
316
- // Prevent infinite recursion
317
- logger.warn('Maximum list nesting level reached');
318
- return;
319
- }
319
+ // /**
320
+ // * Gather runs from any text/image/paragraph in <td>
321
+ // * (including nested <other> tags).
322
+ // */
323
+ // private gatherRunsFromAllParagraphs(children: any[]): Run[] {
324
+ // const runs: Run[] = [];
325
+ // for (const child of children || []) {
326
+ // if (child.type === 'text' || child.type === 'image') {
327
+ // runs.push(this.nodeToRun(child));
328
+ // } else if (child.type === 'paragraph') {
329
+ // runs.push(...this.gatherRuns(child.children));
330
+ // } else if (child.type === 'other' || child.type === 'table' || child.type === 'list') {
331
+ // // recursively gather
332
+ // runs.push(...this.gatherRunsFromAllParagraphs(child.children));
333
+ // }
334
+ // }
335
+ // return runs;
336
+ // }
320
337
 
321
- for (const child of children || []) {
322
- if (child.type === 'other') {
323
- const tn = (child.tagName || '').toLowerCase();
324
- if (tn === 'li') {
325
- // Parse a list item
326
- const item = this.parseListItem(child, level);
327
- list.listItems.push(item);
328
- } else {
329
- // Recurse into other nodes
330
- this.parseListChildren(child.children, list, level + 1);
331
- }
332
- } else {
333
- //skip
334
- continue;
335
- }
336
- }
337
- }
338
+ // /**
339
+ // * Parses a given node to create a List object.
340
+ // *
341
+ // * @param node - The node to parse, expected to have properties `isOrdered` and `children`.
342
+ // * @returns A List object with the parsed data.
343
+ // */
344
+ // private parseList(node: any): List {
345
+ // const list: List = {
346
+ // type: 'list',
347
+ // isOrdered: node.isOrdered,
348
+ // listItems: [],
349
+ // };
338
350
 
339
- /**
340
- * Parses a list item node and converts it into a `ListItem` object.
341
- *
342
- * @param liNode - The list item node to parse.
343
- * @param level - The nesting level of the list item.
344
- * @returns A `ListItem` object containing the parsed list item data.
345
- */
346
- private parseListItem(liNode: any, level: number): ListItem {
347
- const items = this.gatherRunsFromAllParagraphs(liNode.children);
351
+ // this.parseListChildren(node.children, list);
352
+ // return list;
353
+ // }
348
354
 
349
- return {
350
- Runs: items,
351
- level: level,
352
- };
353
- }
355
+ // /**
356
+ // * Parses the children of a list and adds them to the provided list object.
357
+ // *
358
+ // * @param children - An array of child nodes to be parsed.
359
+ // * @param list - The list object to which parsed items will be added.
360
+ // * @param level - The current depth level of the list (default is 0).
361
+ // */
362
+ // private parseListChildren(children: any[], list: List, level: number = 0): void {
363
+ // if (level > 10) {
364
+ // // Prevent infinite recursion
365
+ // logger.warn('Maximum list nesting level reached');
366
+ // return;
367
+ // }
354
368
 
355
- /**
356
- * Builds an array of document elements (Paragraph, Table, or List) from an array of RichNode objects.
357
- *
358
- * @param nodes - An array of RichNode objects to be parsed into document elements.
359
- * @returns An array of Paragraph, Table, or List elements.
360
- */
361
- private buildDocFromNodes(nodes: RichNode[]): Array<Paragraph | Table | List> {
362
- const results: Array<Paragraph | Table | List> = [];
363
- for (const node of nodes) {
364
- try {
365
- const items = this.parseNode(node);
366
- if (Array.isArray(items)) {
367
- results.push(...items);
368
- } else if (items) {
369
- results.push(items);
370
- }
371
- } catch (err: any) {
372
- logger.error(`Error parsing node: ${err.message}`);
373
- // Continue processing other nodes
374
- continue;
375
- }
376
- }
377
- return results;
378
- }
369
+ // for (const child of children || []) {
370
+ // if (child.type === 'other') {
371
+ // const tn = (child.tagName || '').toLowerCase();
372
+ // if (tn === 'li') {
373
+ // // Parse a list item
374
+ // const item = this.parseListItem(child, level);
375
+ // list.listItems.push(item);
376
+ // } else {
377
+ // // Recurse into other nodes
378
+ // this.parseListChildren(child.children, list, level + 1);
379
+ // }
380
+ // } else {
381
+ // //skip
382
+ // continue;
383
+ // }
384
+ // }
385
+ // }
386
+
387
+ // /**
388
+ // * Parses a list item node and converts it into a `ListItem` object.
389
+ // *
390
+ // * @param liNode - The list item node to parse.
391
+ // * @param level - The nesting level of the list item.
392
+ // * @returns A `ListItem` object containing the parsed list item data.
393
+ // */
394
+ // private parseListItem(liNode: any, level: number): ListItem {
395
+ // const items = this.gatherRunsFromAllParagraphs(liNode.children);
396
+
397
+ // return {
398
+ // Runs: items,
399
+ // level: level,
400
+ // };
401
+ // }
402
+
403
+ // /**
404
+ // * Builds an array of document elements (Paragraph, Table, or List) from an array of RichNode objects.
405
+ // *
406
+ // * @param nodes - An array of RichNode objects to be parsed into document elements.
407
+ // * @returns An array of Paragraph, Table, or List elements.
408
+ // */
409
+ // private buildDocFromNodes(nodes: RichNode[]): Array<Paragraph | Table | List> {
410
+ // const results: Array<Paragraph | Table | List> = [];
411
+ // for (const node of nodes) {
412
+ // try {
413
+ // const items = this.parseNode(node);
414
+ // if (Array.isArray(items)) {
415
+ // results.push(...items);
416
+ // } else if (items) {
417
+ // results.push(items);
418
+ // }
419
+ // } catch (err: any) {
420
+ // logger.error(`Error parsing node: ${err.message}`);
421
+ // // Continue processing other nodes
422
+ // continue;
423
+ // }
424
+ // }
425
+ // return results;
426
+ // }
379
427
  } //class