@elisra-devops/docgen-skins 0.10.6 → 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,339 +1,71 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
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"));
9
+ const logger_1 = __importDefault(require("../../../services/logger"));
3
10
  class JSONRichTextParagraph {
4
11
  constructor(field, paragraphStyles, wiId, headingLevel, skipImageFormat = false) {
5
12
  this.paragraphStyles = paragraphStyles;
6
13
  this.wiId = wiId;
7
- this.paragraphTemplate = this.buildDocFromNodes(field.richTextNodes);
8
- } //constructor
9
- getJSONRichTextParagraph() {
10
- return this.paragraphTemplate;
11
- } //getJSONTable
12
- /**
13
- * Parses a given RichNode and returns a corresponding Paragraph, Table, List,
14
- * an array of these types, or null if the node type is not recognized.
15
- *
16
- * @param node - The RichNode to be parsed.
17
- * @returns A Paragraph, Table, List, an array of these types, or null.
18
- *
19
- * The function handles different node types as follows:
20
- * - 'paragraph': Parses the node as a paragraph.
21
- * - 'table': Parses the node as a table.
22
- * - 'list': Parses the node as a list.
23
- * - 'text', 'image', 'break': Converts the node to a paragraph with a single run.
24
- * - 'other': Recursively parses child nodes and returns an array of results.
25
- * - Default: Returns null for unrecognized node types.
26
- */
27
- parseNode(node) {
28
- switch (node.type) {
29
- case 'paragraph':
30
- return this.parseParagraphNode(node);
31
- case 'table':
32
- return this.parseTableNode(node);
33
- case 'list':
34
- return this.parseList(node);
35
- case 'text':
36
- case 'image':
37
- case 'break':
38
- return { type: 'paragraph', runs: [this.nodeToRun(node)] };
39
- case 'other':
40
- let childrenResults = [];
41
- for (const child of node.children) {
42
- const childResult = this.parseNode(child);
43
- if (Array.isArray(childResult)) {
44
- childrenResults.push(...childResult);
45
- }
46
- else if (childResult) {
47
- childrenResults.push(childResult);
48
- }
49
- }
50
- return childrenResults.length > 0 ? childrenResults : null;
51
- default:
52
- return null;
53
- }
54
- }
55
- /**
56
- * Parses a paragraph node and converts it into a Paragraph object.
57
- *
58
- * @param node - The node to parse, expected to have a `children` property.
59
- * @returns A Paragraph object containing the parsed runs.
60
- */
61
- parseParagraphNode(node) {
62
- const runs = this.gatherRuns(node.children);
63
- return { type: 'paragraph', runs };
64
- }
65
- /**
66
- * Gathers runs from the provided children nodes.
67
- *
68
- * This method processes an array of child nodes and converts them into an array of `Run` objects.
69
- * It handles different types of nodes such as text, image, break, paragraph, table, list, and other.
70
- *
71
- * - For `text`, `image`, and `break` nodes, it directly converts them to `Run` objects.
72
- * - For `paragraph` nodes, it recursively gathers runs from the child paragraphs.
73
- * - For `table` and `list` nodes, it adds a placeholder `Run` object indicating the embedded type.
74
- * - For `other` nodes, it recursively gathers runs from the child nodes.
75
- *
76
- * @param children - An array of child nodes to process.
77
- * @returns An array of `Run` objects representing the gathered runs.
78
- */
79
- gatherRuns(children) {
80
- const runs = [];
81
- for (const child of children || []) {
82
- if (child.type === 'text' || child.type === 'image' || child.type === 'break') {
83
- runs.push(this.nodeToRun(child));
84
- }
85
- else if (child.type === 'paragraph') {
86
- // Recursively gather runs from child paragraphs
87
- runs.push(...this.gatherRuns(child.children));
88
- }
89
- else if (child.type === 'table' || child.type === 'list') {
90
- // Not supported in this context, so we'll just add a placeholder
91
- runs.push({ type: 'other', value: `[Embedded ${child.type}]` });
92
- }
93
- else if (child.type === 'other') {
94
- // Recursively gather runs from inside <span> or <b>, etc.
95
- // TODO: Handle b and i, u tags and more relevant tags for text styling
96
- runs.push(...this.gatherRuns(child.children));
97
- }
14
+ this.paragraphTemplate = this.generateJsonRichTextParagraphs(field, this.paragraphStyles, skipImageFormat);
15
+ if (headingLevel && field.name === 'Title: ') {
16
+ this.paragraphTemplate.headingLevel = headingLevel;
98
17
  }
99
- return runs;
100
- }
101
- /**
102
- * Converts a node object to a Run object based on its type and text styling.
103
- *
104
- * @param node - The node object to be converted. It can be of type 'text', 'image', or 'break'.
105
- * @returns A Run object with the appropriate type and properties based on the input node.
106
- *
107
- * The Run object can have the following structure:
108
- * - For 'text' nodes: { type: 'text', value: string, textStyling: object }
109
- * - For 'image' nodes: { type: 'image', value: '', src: string }
110
- * - For 'break' nodes: { type: 'break' }
111
- * - For other types: { type: 'other', value: '' }
112
- *
113
- * The textStyling object includes:
114
- * - Bold: boolean
115
- * - Italic: boolean
116
- * - Underline: boolean
117
- * - Size: number
118
- * - Uri: string | null
119
- * - Font: string
120
- * - InsertLineBreak: boolean
121
- * - InsertSpace: boolean
122
- */
123
- nodeToRun(node) {
124
- var _a, _b, _c, _d;
125
- const textStyling = {
126
- Bold: ((_a = node.textStyling) === null || _a === void 0 ? void 0 : _a.Bold) || this.paragraphStyles.isBold,
127
- Italic: ((_b = node.textStyling) === null || _b === void 0 ? void 0 : _b.Italic) || this.paragraphStyles.IsItalic,
128
- Underline: ((_c = node.textStyling) === null || _c === void 0 ? void 0 : _c.Underline) || this.paragraphStyles.IsUnderline,
129
- Size: this.paragraphStyles.Size || 12,
130
- Uri: this.paragraphStyles.Uri || null,
131
- Font: this.paragraphStyles.Font || 'Arial',
132
- InsertLineBreak: this.paragraphStyles.InsertLineBreak || false,
133
- InsertSpace: ((_d = node.textStyling) === null || _d === void 0 ? void 0 : _d.InsertSpace) || this.paragraphStyles.InsertSpace,
134
- };
135
- if (node.type === 'text') {
136
- return { type: 'text', value: node.value, textStyling: textStyling };
137
- }
138
- else if (node.type === 'image') {
139
- return { type: 'image', value: '', src: node.src || '' };
140
- }
141
- else if (node.type === 'break') {
142
- return { type: 'break' };
143
- }
144
- else {
145
- return { type: 'other', value: '' };
146
- }
147
- }
148
- /**
149
- * Converts a given node object into a Table structure.
150
- *
151
- * @remarks
152
- * This function processes the children of the specified node and
153
- * transforms them into a table representation, adding default properties
154
- * such as heading level, page break insertion, and an empty rows array.
155
- *
156
- * @param node - The node object containing the structural details needed
157
- * to create a table.
158
- * @returns A fully constructed Table object with the parsed node data.
159
- */
160
- parseTableNode(node) {
161
- const table = {
162
- type: 'table',
163
- headingLevel: 0,
164
- insertPageBreak: false,
165
- Rows: [],
166
- };
167
- this.parseTableChildren(node.children, table);
168
- return table;
169
- }
170
- /**
171
- * Parses child elements of a table structure and updates the provided Table instance accordingly.
172
- *
173
- * @param children - An array of child nodes to be evaluated for table content.
174
- * @param table - The Table object to which parsed rows and nested structures will be appended.
175
- *
176
- * @remarks
177
- * This method recursively traverses and identifies relevant table elements (e.g., <tr>, <thead>, <tbody>, etc.)
178
- * to generate the final row data for the given Table instance.
179
- */
180
- parseTableChildren(children, table) {
181
- for (const child of children || []) {
182
- if (child.type === 'other') {
183
- const tn = (child.tagName || '').toLowerCase();
184
- if (tn === 'tr') {
185
- // Parse a table row
186
- const row = this.parseTableRow(child);
187
- table.Rows.push(row);
188
- }
189
- else if (tn === 'thead' || tn === 'tbody' || tn === 'tfoot') {
190
- // Recurse into thead/tbody/tfoot
191
- this.parseTableChildren(child.children, table);
192
- }
193
- else {
194
- // Recurse into other nodes
195
- this.parseTableChildren(child.children, table);
196
- }
197
- }
198
- else if (child.type === 'table') {
199
- this.parseTableChildren(child.children, table);
200
- }
201
- else {
202
- //skip
203
- continue;
204
- }
205
- }
206
- }
207
- /**
208
- * Parses the given table row node and extracts its cells by iterating through its child elements.
209
- * Each child element that is recognized as a table cell (td or th) is converted into a corresponding cell object.
210
- *
211
- * @param trNode - An AST node representing the table row, containing possible table cell or header elements.
212
- * @returns A TableRow object containing an array of processed cells.
213
- */
214
- parseTableRow(trNode) {
215
- const row = { Cells: [] };
216
- // parse <td> or <th> inside this <tr>
217
- for (const child of trNode.children || []) {
218
- if (child.type === 'other' && (child.tagName === 'td' || child.tagName === 'th')) {
219
- row.Cells.push(this.parseTableCell(child));
220
- }
221
- else {
222
- // skip or recurse
223
- }
224
- }
225
- return row;
226
- }
227
- /**
228
- * Build one TableCell from <td> node
229
- */
230
- parseTableCell(tdNode) {
231
- // We'll collect everything in one paragraph
232
- const cellParagraphRuns = this.gatherRunsFromAllParagraphs(tdNode.children);
233
- return {
234
- Paragraphs: [
235
- {
236
- Runs: cellParagraphRuns,
237
- },
238
- ],
239
- };
240
- }
241
- /**
242
- * Gather runs from any text/image/paragraph in <td>
243
- * (including nested <other> tags).
244
- */
245
- gatherRunsFromAllParagraphs(children) {
246
- const runs = [];
247
- for (const child of children || []) {
248
- if (child.type === 'text' || child.type === 'image') {
249
- runs.push(this.nodeToRun(child));
250
- }
251
- else if (child.type === 'paragraph') {
252
- runs.push(...this.gatherRuns(child.children));
253
- }
254
- else if (child.type === 'other' || child.type === 'table' || child.type === 'list') {
255
- // recursively gather
256
- runs.push(...this.gatherRunsFromAllParagraphs(child.children));
257
- }
258
- }
259
- return runs;
260
- }
261
- /**
262
- * Parses a given node to create a List object.
263
- *
264
- * @param node - The node to parse, expected to have properties `isOrdered` and `children`.
265
- * @returns A List object with the parsed data.
266
- */
267
- parseList(node) {
268
- const list = {
269
- type: 'list',
270
- isOrdered: node.isOrdered,
271
- listItems: [],
272
- };
273
- this.parseListChildren(node.children, list);
274
- return list;
275
- }
276
- /**
277
- * Parses the children of a list and adds them to the provided list object.
278
- *
279
- * @param children - An array of child nodes to be parsed.
280
- * @param list - The list object to which parsed items will be added.
281
- * @param level - The current depth level of the list (default is 0).
282
- */
283
- parseListChildren(children, list, level = 0) {
284
- for (const child of children || []) {
285
- if (child.type === 'other') {
286
- const tn = (child.tagName || '').toLowerCase();
287
- if (tn === 'li') {
288
- // Parse a list item
289
- const item = this.parseListItem(child, level);
290
- list.listItems.push(item);
291
- }
292
- else {
293
- // Recurse into other nodes
294
- 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;
295
57
  }
296
- }
297
- else {
298
- //skip
299
- continue;
300
- }
58
+ });
59
+ return richTextSkin;
301
60
  }
302
- }
303
- /**
304
- * Parses a list item node and converts it into a `ListItem` object.
305
- *
306
- * @param liNode - The list item node to parse.
307
- * @param level - The nesting level of the list item.
308
- * @returns A `ListItem` object containing the parsed list item data.
309
- */
310
- parseListItem(liNode, level) {
311
- const items = this.gatherRunsFromAllParagraphs(liNode.children);
312
- return {
313
- Runs: items,
314
- level: level,
315
- };
316
- }
317
- /**
318
- * Builds an array of document elements (Paragraph, Table, or List) from an array of RichNode objects.
319
- *
320
- * @param nodes - An array of RichNode objects to be parsed into document elements.
321
- * @returns An array of Paragraph, Table, or List elements.
322
- */
323
- buildDocFromNodes(nodes) {
324
- const results = [];
325
- for (const node of nodes) {
326
- const items = this.parseNode(node);
327
- // parseNode might return a single Paragraph/Table or an array
328
- if (Array.isArray(items)) {
329
- results.push(...items);
330
- }
331
- else if (items) {
332
- results.push(items);
333
- }
61
+ catch (e) {
62
+ logger_1.default.warn(e);
63
+ return [];
334
64
  }
335
- return results;
336
- }
65
+ } //generateJsonRichTextParagraphs
66
+ getJSONRichTextParagraph() {
67
+ return this.paragraphTemplate;
68
+ } //getJSONRichTextParagraph
337
69
  } //class
338
70
  exports.default = JSONRichTextParagraph;
339
71
  //# sourceMappingURL=JSONRichTextParagraph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"JSONRichTextParagraph.js","sourceRoot":"","sources":["../../../../src/models/json/paragraph/JSONRichTextParagraph.ts"],"names":[],"mappings":";;AAaA,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,QAAQ,IAAI,CAAC,IAAI,EAAE;YACjB,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACvC,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACnC,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC9B,KAAK,MAAM,CAAC;YACZ,KAAK,OAAO,CAAC;YACb,KAAK,OAAO;gBACV,OAAO,EAAE,IA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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.6",
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
  );
@@ -479,7 +485,7 @@ export default class Skins {
479
485
  }
480
486
 
481
487
  try {
482
- if (testcase.testCaseStepsSkinData.length > 0) {
488
+ if (testcase.testCaseStepsSkinData?.length > 0) {
483
489
  let testProcedureTitleParagraph = new JSONParagraph(
484
490
  { name: 'Title', value: 'Test Procedure:' },
485
491
  DescriptionandProcedureStyle,
@@ -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,
@@ -539,7 +545,6 @@ export default class Skins {
539
545
  });
540
546
  });
541
547
  return testSkin;
542
- break;
543
548
  case 'html':
544
549
  logger.info(`Generating html test data!`);
545
550
  break;
@@ -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;