@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.
@@ -3,350 +3,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const JSONHtml_1 = __importDefault(require("../html/JSONHtml"));
7
+ const JSONParagraph_1 = __importDefault(require("./JSONParagraph"));
8
+ const JSONTable_1 = __importDefault(require("../table/JSONTable"));
6
9
  const logger_1 = __importDefault(require("../../../services/logger"));
7
10
  class JSONRichTextParagraph {
8
11
  constructor(field, paragraphStyles, wiId, headingLevel, skipImageFormat = false) {
9
12
  this.paragraphStyles = paragraphStyles;
10
13
  this.wiId = wiId;
11
- this.paragraphTemplate = this.buildDocFromNodes(field.richTextNodes);
12
- } //constructor
13
- getJSONRichTextParagraph() {
14
- return this.paragraphTemplate;
15
- } //getJSONTable
16
- /**
17
- * Parses a given RichNode and returns a corresponding Paragraph, Table, List,
18
- * an array of these types, or null if the node type is not recognized.
19
- *
20
- * @param node - The RichNode to be parsed.
21
- * @returns A Paragraph, Table, List, an array of these types, or null.
22
- *
23
- * The function handles different node types as follows:
24
- * - 'paragraph': Parses the node as a paragraph.
25
- * - 'table': Parses the node as a table.
26
- * - 'list': Parses the node as a list.
27
- * - 'text', 'image', 'break': Converts the node to a paragraph with a single run.
28
- * - 'other': Recursively parses child nodes and returns an array of results.
29
- * - Default: Returns null for unrecognized node types.
30
- */
31
- parseNode(node) {
32
- if (!node || typeof node.type !== 'string') {
33
- logger_1.default.warn(`Invalid node structure: ${JSON.stringify(node)}`);
34
- return null;
35
- }
36
- switch (node.type) {
37
- case 'paragraph':
38
- return this.parseParagraphNode(node);
39
- case 'table':
40
- return this.parseTableNode(node);
41
- case 'list':
42
- return this.parseList(node);
43
- case 'text':
44
- case 'image':
45
- case 'break':
46
- return { type: 'paragraph', runs: [this.nodeToRun(node)] };
47
- case 'other':
48
- let childrenResults = [];
49
- for (const child of node.children) {
50
- const childResult = this.parseNode(child);
51
- if (Array.isArray(childResult)) {
52
- childrenResults.push(...childResult);
53
- }
54
- else if (childResult) {
55
- childrenResults.push(childResult);
56
- }
57
- }
58
- return childrenResults.length > 0 ? childrenResults : null;
59
- default:
60
- return null;
61
- }
62
- }
63
- /**
64
- * Parses a paragraph node and converts it into a Paragraph object.
65
- *
66
- * @param node - The node to parse, expected to have a `children` property.
67
- * @returns A Paragraph object containing the parsed runs.
68
- */
69
- parseParagraphNode(node) {
70
- const runs = this.gatherRuns(node.children);
71
- return { type: 'paragraph', runs };
72
- }
73
- /**
74
- * Gathers runs from the provided children nodes.
75
- *
76
- * This method processes an array of child nodes and converts them into an array of `Run` objects.
77
- * It handles different types of nodes such as text, image, break, paragraph, table, list, and other.
78
- *
79
- * - For `text`, `image`, and `break` nodes, it directly converts them to `Run` objects.
80
- * - For `paragraph` nodes, it recursively gathers runs from the child paragraphs.
81
- * - For `table` and `list` nodes, it adds a placeholder `Run` object indicating the embedded type.
82
- * - For `other` nodes, it recursively gathers runs from the child nodes.
83
- *
84
- * @param children - An array of child nodes to process.
85
- * @returns An array of `Run` objects representing the gathered runs.
86
- */
87
- gatherRuns(children) {
88
- const runs = [];
89
- if (!Array.isArray(children)) {
90
- logger_1.default.warn(`Invalid children structure: ${JSON.stringify(children)}`);
91
- return runs;
92
- }
93
- for (const child of children || []) {
94
- if (child.type === 'text' || child.type === 'image' || child.type === 'break') {
95
- runs.push(this.nodeToRun(child));
96
- }
97
- else if (child.type === 'paragraph') {
98
- // Recursively gather runs from child paragraphs
99
- runs.push(...this.gatherRuns(child.children));
100
- }
101
- else if (child.type === 'table' || child.type === 'list') {
102
- // Not supported in this context, so we'll just add a placeholder
103
- runs.push({ type: 'other', value: `[Embedded ${child.type}]` });
104
- }
105
- else if (child.type === 'other') {
106
- // Recursively gather runs from inside <span> or <b>, etc.
107
- // TODO: Handle b and i, u tags and more relevant tags for text styling
108
- runs.push(...this.gatherRuns(child.children));
109
- }
110
- }
111
- return runs;
112
- }
113
- /**
114
- * Converts a node object to a Run object based on its type and text styling.
115
- *
116
- * @param node - The node object to be converted. It can be of type 'text', 'image', or 'break'.
117
- * @returns A Run object with the appropriate type and properties based on the input node.
118
- *
119
- * The Run object can have the following structure:
120
- * - For 'text' nodes: { type: 'text', value: string, textStyling: object }
121
- * - For 'image' nodes: { type: 'image', value: '', src: string }
122
- * - For 'break' nodes: { type: 'break' }
123
- * - For other types: { type: 'other', value: '' }
124
- *
125
- * The textStyling object includes:
126
- * - Bold: boolean
127
- * - Italic: boolean
128
- * - Underline: boolean
129
- * - Size: number
130
- * - Uri: string | null
131
- * - Font: string
132
- * - InsertLineBreak: boolean
133
- * - InsertSpace: boolean
134
- */
135
- nodeToRun(node) {
136
- const textStyling = Object.assign(Object.assign(Object.assign({}, this.paragraphStyles), node.textStyling), { Size: this.paragraphStyles.Size || 12, Uri: this.paragraphStyles.Uri || null, Font: this.paragraphStyles.Font || 'Arial', InsertLineBreak: this.paragraphStyles.InsertLineBreak || false });
137
- if (node.type === 'text') {
138
- return { type: 'text', value: node.value, textStyling: textStyling };
139
- }
140
- else if (node.type === 'image') {
141
- return { type: 'image', value: '', src: node.src || '' };
142
- }
143
- else if (node.type === 'break') {
144
- return { type: 'break' };
145
- }
146
- else {
147
- return { type: 'other', value: '' };
148
- }
149
- }
150
- /**
151
- * Converts a given node object into a Table structure.
152
- *
153
- * @remarks
154
- * This function processes the children of the specified node and
155
- * transforms them into a table representation, adding default properties
156
- * such as heading level, page break insertion, and an empty rows array.
157
- *
158
- * @param node - The node object containing the structural details needed
159
- * to create a table.
160
- * @returns A fully constructed Table object with the parsed node data.
161
- */
162
- parseTableNode(node) {
163
- const table = {
164
- type: 'table',
165
- headingLevel: 0,
166
- insertPageBreak: false,
167
- Rows: [],
168
- };
169
- this.parseTableChildren(node.children, table);
170
- return table;
171
- }
172
- /**
173
- * Parses child elements of a table structure and updates the provided Table instance accordingly.
174
- *
175
- * @param children - An array of child nodes to be evaluated for table content.
176
- * @param table - The Table object to which parsed rows and nested structures will be appended.
177
- *
178
- * @remarks
179
- * This method recursively traverses and identifies relevant table elements (e.g., <tr>, <thead>, <tbody>, etc.)
180
- * to generate the final row data for the given Table instance.
181
- */
182
- parseTableChildren(children, table) {
183
- for (const child of children || []) {
184
- if (child.type === 'other') {
185
- const tn = (child.tagName || '').toLowerCase();
186
- if (tn === 'tr') {
187
- // Parse a table row
188
- const row = this.parseTableRow(child);
189
- table.Rows.push(row);
190
- }
191
- else if (tn === 'thead' || tn === 'tbody' || tn === 'tfoot') {
192
- // Recurse into thead/tbody/tfoot
193
- this.parseTableChildren(child.children, table);
194
- }
195
- else {
196
- // Recurse into other nodes
197
- this.parseTableChildren(child.children, table);
198
- }
199
- }
200
- else if (child.type === 'table') {
201
- this.parseTableChildren(child.children, table);
202
- }
203
- else {
204
- //skip
205
- continue;
206
- }
207
- }
208
- }
209
- /**
210
- * Parses the given table row node and extracts its cells by iterating through its child elements.
211
- * Each child element that is recognized as a table cell (td or th) is converted into a corresponding cell object.
212
- *
213
- * @param trNode - An AST node representing the table row, containing possible table cell or header elements.
214
- * @returns A TableRow object containing an array of processed cells.
215
- */
216
- parseTableRow(trNode) {
217
- const row = { Cells: [] };
218
- // parse <td> or <th> inside this <tr>
219
- for (const child of trNode.children || []) {
220
- if (child.type === 'other' && (child.tagName === 'td' || child.tagName === 'th')) {
221
- row.Cells.push(this.parseTableCell(child));
222
- }
223
- else {
224
- // skip or recurse
225
- }
226
- }
227
- return row;
228
- }
229
- /**
230
- * Build one TableCell from <td> node
231
- */
232
- parseTableCell(tdNode) {
233
- // We'll collect everything in one paragraph
234
- const cellParagraphRuns = this.gatherRunsFromAllParagraphs(tdNode.children);
235
- return {
236
- Paragraphs: [
237
- {
238
- Runs: cellParagraphRuns,
239
- },
240
- ],
241
- };
242
- }
243
- /**
244
- * Gather runs from any text/image/paragraph in <td>
245
- * (including nested <other> tags).
246
- */
247
- gatherRunsFromAllParagraphs(children) {
248
- const runs = [];
249
- for (const child of children || []) {
250
- if (child.type === 'text' || child.type === 'image') {
251
- runs.push(this.nodeToRun(child));
252
- }
253
- else if (child.type === 'paragraph') {
254
- runs.push(...this.gatherRuns(child.children));
255
- }
256
- else if (child.type === 'other' || child.type === 'table' || child.type === 'list') {
257
- // recursively gather
258
- runs.push(...this.gatherRunsFromAllParagraphs(child.children));
259
- }
260
- }
261
- return runs;
262
- }
263
- /**
264
- * Parses a given node to create a List object.
265
- *
266
- * @param node - The node to parse, expected to have properties `isOrdered` and `children`.
267
- * @returns A List object with the parsed data.
268
- */
269
- parseList(node) {
270
- const list = {
271
- type: 'list',
272
- isOrdered: node.isOrdered,
273
- listItems: [],
274
- };
275
- this.parseListChildren(node.children, list);
276
- return list;
277
- }
278
- /**
279
- * Parses the children of a list and adds them to the provided list object.
280
- *
281
- * @param children - An array of child nodes to be parsed.
282
- * @param list - The list object to which parsed items will be added.
283
- * @param level - The current depth level of the list (default is 0).
284
- */
285
- parseListChildren(children, list, level = 0) {
286
- if (level > 10) {
287
- // Prevent infinite recursion
288
- logger_1.default.warn('Maximum list nesting level reached');
289
- return;
14
+ this.paragraphTemplate = this.generateJsonRichTextParagraphs(field, this.paragraphStyles, skipImageFormat);
15
+ if (headingLevel && field.name === 'Title: ') {
16
+ this.paragraphTemplate.headingLevel = headingLevel;
290
17
  }
291
- for (const child of children || []) {
292
- if (child.type === 'other') {
293
- const tn = (child.tagName || '').toLowerCase();
294
- if (tn === 'li') {
295
- // Parse a list item
296
- const item = this.parseListItem(child, level);
297
- list.listItems.push(item);
298
- }
299
- else {
300
- // Recurse into other nodes
301
- this.parseListChildren(child.children, list, level + 1);
18
+ } //constructor
19
+ generateJsonRichTextParagraphs(field, paragraphStyles, skipImageFormat = false) {
20
+ let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
21
+ titleStyle.isBold = true;
22
+ titleStyle.IsUnderline = true;
23
+ titleStyle.InsertSpace = true;
24
+ titleStyle.InsertLineBreak = false;
25
+ let richTextSkin = [];
26
+ //handle rich text
27
+ try {
28
+ field.richText.forEach((content) => {
29
+ switch (content.type) {
30
+ case 'paragraph':
31
+ content.data.fields.forEach((richTextField) => {
32
+ if (/<\/?[a-z][\s\S]*>/.test(richTextField.value)) {
33
+ let html = new JSONHtml_1.default(richTextField.value);
34
+ richTextSkin.push(html.getJSONHtml());
35
+ }
36
+ else {
37
+ //making sure ID is not printed
38
+ let paragraphSkin = new JSONParagraph_1.default(richTextField, paragraphStyles, 0, 0);
39
+ richTextSkin.push(paragraphSkin.getJSONParagraph());
40
+ }
41
+ });
42
+ break;
43
+ case 'picture':
44
+ if (!skipImageFormat) {
45
+ richTextSkin.push({
46
+ type: 'picture',
47
+ Path: content.data,
48
+ });
49
+ }
50
+ break;
51
+ case 'table':
52
+ if (content.data) {
53
+ let tableSkin = new JSONTable_1.default(content.data, undefined, paragraphStyles, 0);
54
+ richTextSkin.push(tableSkin.getJSONTable());
55
+ }
56
+ break;
302
57
  }
303
- }
304
- else {
305
- //skip
306
- continue;
307
- }
58
+ });
59
+ return richTextSkin;
308
60
  }
309
- }
310
- /**
311
- * Parses a list item node and converts it into a `ListItem` object.
312
- *
313
- * @param liNode - The list item node to parse.
314
- * @param level - The nesting level of the list item.
315
- * @returns A `ListItem` object containing the parsed list item data.
316
- */
317
- parseListItem(liNode, level) {
318
- const items = this.gatherRunsFromAllParagraphs(liNode.children);
319
- return {
320
- Runs: items,
321
- level: level,
322
- };
323
- }
324
- /**
325
- * Builds an array of document elements (Paragraph, Table, or List) from an array of RichNode objects.
326
- *
327
- * @param nodes - An array of RichNode objects to be parsed into document elements.
328
- * @returns An array of Paragraph, Table, or List elements.
329
- */
330
- buildDocFromNodes(nodes) {
331
- const results = [];
332
- for (const node of nodes) {
333
- try {
334
- const items = this.parseNode(node);
335
- if (Array.isArray(items)) {
336
- results.push(...items);
337
- }
338
- else if (items) {
339
- results.push(items);
340
- }
341
- }
342
- catch (err) {
343
- logger_1.default.error(`Error parsing node: ${err.message}`);
344
- // Continue processing other nodes
345
- continue;
346
- }
61
+ catch (e) {
62
+ logger_1.default.warn(e);
63
+ return [];
347
64
  }
348
- return results;
349
- }
65
+ } //generateJsonRichTextParagraphs
66
+ getJSONRichTextParagraph() {
67
+ return this.paragraphTemplate;
68
+ } //getJSONRichTextParagraph
350
69
  } //class
351
70
  exports.default = JSONRichTextParagraph;
352
71
  //# sourceMappingURL=JSONRichTextParagraph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"JSONRichTextParagraph.js","sourceRoot":"","sources":["../../../../src/models/json/paragraph/JSONRichTextParagraph.ts"],"names":[],"mappings":";;;;;AAAA,sEAA8C;AAc9C,MAAqB,qBAAqB;IAIxC,YACE,KAAiB,EACjB,eAA6B,EAC7B,IAAY,EACZ,YAAoB,EACpB,eAAe,GAAG,KAAK;QAEvB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACvE,CAAC,CAAC,aAAa;IAEf,wBAAwB;QACtB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC,CAAC,cAAc;IAEhB;;;;;;;;;;;;;;OAcG;IACK,SAAS,CAAC,IAAc;QAC9B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC1C,gBAAM,CAAC,IAAI,CAAC,2BAA2B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC;SACb;QAED,QAAQ,IAAI,CAAC,IAAI,EAAE;YACjB,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACvC,KAAK,OAAO;gBAC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,IAAI,CAAC,KAAK,CAAC,CAAC;iBACrB;aACF;YAAC,OAAO,GAAQ,EAAE;gBACjB,gBAAM,CAAC,KAAK,CAAC,uBAAuB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnD,kCAAkC;gBAClC,SAAS;aACV;SACF;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC,OAAO;AA5WT,wCA4WC"}
1
+ {"version":3,"file":"JSONRichTextParagraph.js","sourceRoot":"","sources":["../../../../src/models/json/paragraph/JSONRichTextParagraph.ts"],"names":[],"mappings":";;;;;AACA,gEAAwC;AACxC,oEAA4C;AAC5C,mEAA2C;AAC3C,sEAA8C;AAE9C,MAAqB,qBAAqB;IAIxC,YACE,KAAiB,EACjB,eAA6B,EAC7B,IAAY,EACZ,YAAoB,EACpB,eAAe,GAAG,KAAK;QAEvB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,8BAA8B,CAC1D,KAAK,EACL,IAAI,CAAC,eAAe,EACpB,eAAe,CAChB,CAAC;QACF,IAAI,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;YAC5C,IAAI,CAAC,iBAAiB,CAAC,YAAY,GAAG,YAAY,CAAC;SACpD;IACH,CAAC,CAAC,aAAa;IAEf,8BAA8B,CAAC,KAAiB,EAAE,eAAe,EAAE,eAAe,GAAG,KAAK;QACxF,IAAI,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC;QAE7D,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC;QACzB,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC;QAC9B,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC;QAC9B,UAAU,CAAC,eAAe,GAAG,KAAK,CAAC;QAEnC,IAAI,YAAY,GAAU,EAAE,C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,CAAC,CAAC,CAAC,CAAC;YACf,OAAO,EAAE,CAAC;SACX;IACH,CAAC,CAAC,gCAAgC;IAElC,wBAAwB;QACtB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC,CAAC,0BAA0B;CA0V7B,CAAC,OAAO;AApaT,wCAoaC"}
@@ -53,7 +53,8 @@ export interface Attachment {
53
53
  isLinkedFile?: boolean;
54
54
  IsFlattened?: boolean;
55
55
  }
56
- interface TextStyle {
56
+ export interface Run {
57
+ text: string;
57
58
  Bold: boolean;
58
59
  Italic: boolean;
59
60
  Underline: boolean;
@@ -62,12 +63,7 @@ interface TextStyle {
62
63
  Font: string;
63
64
  InsertLineBreak: boolean;
64
65
  InsertSpace: boolean;
65
- }
66
- export interface Run {
67
- type: 'text' | 'image' | 'break' | 'other';
68
- value?: string;
69
66
  src?: string;
70
- textStyling?: TextStyle;
71
67
  }
72
68
  export interface WorkItemData {
73
69
  }
@@ -109,7 +105,7 @@ export interface WIProperty {
109
105
  attachmentLink?: string;
110
106
  attachmentType?: string;
111
107
  relativeAttachmentLink?: string;
112
- richTextNodes?: any[];
108
+ richText?: any[];
113
109
  }
114
110
  export interface MultipeValuesWIProperty {
115
111
  name: string;
@@ -121,42 +117,10 @@ export interface MultipeValuesWIProperty {
121
117
  attachmentLink?: string;
122
118
  attachmentType?: string;
123
119
  relativeAttachmentLink?: string;
124
- richTextNodes?: any[];
120
+ richText?: any[];
125
121
  }
126
122
  export interface WIColumns {
127
123
  name: string;
128
124
  referenceName: string;
129
125
  url: string;
130
126
  }
131
- export type RichNode = ParagraphNode | TextNode | ImageNode | TableNode | ListNode | BreakNode | OtherNode;
132
- export interface ParagraphNode {
133
- type: 'paragraph';
134
- children: RichNode[];
135
- }
136
- export interface TextNode {
137
- type: 'text';
138
- value: string;
139
- }
140
- export interface ImageNode {
141
- type: 'image';
142
- src: string;
143
- alt?: string;
144
- }
145
- export interface BreakNode {
146
- type: 'break';
147
- }
148
- export interface TableNode {
149
- type: 'table';
150
- children: RichNode[];
151
- }
152
- export interface ListNode {
153
- type: 'list';
154
- isOrdered: boolean;
155
- children: RichNode[];
156
- }
157
- export interface OtherNode {
158
- type: 'other';
159
- tagName: string;
160
- children: RichNode[];
161
- }
162
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elisra-devops/docgen-skins",
3
- "version": "0.10.7",
3
+ "version": "0.10.8",
4
4
  "description": "Can be outputed in various types:",
5
5
  "main": "./bin/index.js",
6
6
  "types": "./bin/index.d.ts",
package/src/index.ts CHANGED
@@ -287,7 +287,13 @@ export default class Skins {
287
287
  let wiSkin = new JSONHeaderParagraph(wiHeaderFields, headerStyle, element.id || 0, element.level);
288
288
  testSkins.push(wiSkin.getJSONParagraph());
289
289
 
290
- let wiDescriptionParagraph = new JSONRichTextParagraph(element.fields[2], styles, element.id || 0, 0);
290
+ let wiDescriptionParagraph = new JSONRichTextParagraph(
291
+ element.fields[2],
292
+ styles,
293
+ element.id || 0,
294
+ 0,
295
+ true
296
+ );
291
297
  let richTextDecsSkin: any[] = wiDescriptionParagraph.getJSONRichTextParagraph();
292
298
  testSkins.push(...richTextDecsSkin);
293
299
  }
@@ -430,7 +436,7 @@ export default class Skins {
430
436
 
431
437
  let testDescriptionParagraph = new JSONRichTextParagraph(
432
438
  testcase.testCaseHeaderSkinData.fields[2],
433
- { ...styles, Size: 12, Font: 'Arial' },
439
+ styles,
434
440
  testcase.id || 0,
435
441
  0
436
442
  );
@@ -491,7 +497,7 @@ export default class Skins {
491
497
  let tableSkin = new JSONTable(
492
498
  testcase.testCaseStepsSkinData,
493
499
  headerStyles,
494
- { ...styles, Font: 'Arial' },
500
+ styles,
495
501
  headingLvl,
496
502
  undefined,
497
503
  undefined,
@@ -29,49 +29,45 @@ export default class JSONRun {
29
29
  if (fieldtype !== 'SuiteHeaderParagraphTitle') {
30
30
  text = `${striphtml(text.toString(), { cb: replaceBr })}` || '';
31
31
  }
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;
32
+ run.text = text;
33
+ run.Bold = style.isBold;
34
+ run.Italic = style.IsItalic;
35
+ run.Underline = style.IsUnderline;
36
+ run.Size = style.Size;
38
37
 
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)));
38
+ if (run.Uri === '') {
39
+ run.Uri = null;
40
+ } else {
41
+ run.Uri = style.Uri;
42
+ }
43
+ run.Font = style.Font;
44
+ if (rowArray.length == 1) {
45
+ run.InsertLineBreak = style.InsertLineBreak;
46
+ } else {
47
+ run.InsertLineBreak = false;
55
48
  }
49
+ if (rowArray.length - 1 == i) {
50
+ run.InsertLineBreak = style.InsertLineBreak;
51
+ }
52
+ run.InsertSpace = style.InsertSpace;
53
+ runs.push(JSON.parse(JSON.stringify(run)));
56
54
  });
57
55
  } catch (e) {
58
56
  logger.silly(`${value} - cannot be splitted`);
59
57
  runs[0] = defaultJsonRun;
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;
58
+ runs[0].text = value ? `${striphtml(value.toString(), { cb: replaceBr })}` : ``;
59
+ runs[0].Bold = style.isBold;
60
+ runs[0].Italic = style.IsItalic;
61
+ runs[0].Underline = style.IsUnderline;
62
+ runs[0].Size = style.Size;
63
+ if (runs[0].Uri === '') {
64
+ runs[0].Uri = null;
65
+ } else {
66
+ runs[0].Uri = style.Uri;
74
67
  }
68
+ runs[0].Font = style.Font;
69
+ runs[0].InsertLineBreak = style.InsertLineBreak;
70
+ runs[0].InsertSpace = style.InsertSpace;
75
71
  }
76
72
 
77
73
  return runs;
@@ -1,18 +1,15 @@
1
1
  import { Run, StyleOptions } from './wordJsonModels';
2
2
 
3
3
  export let defaultJsonRun: Run = {
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
- },
4
+ text: ``,
5
+ Bold: false,
6
+ Italic: false,
7
+ Underline: false,
8
+ Size: 12,
9
+ Uri: null,
10
+ Font: 'Arial',
11
+ InsertLineBreak: false,
12
+ InsertSpace: true,
16
13
  };
17
14
 
18
15
  export let DescriptionandProcedureStyle: StyleOptions = {