@elisra-devops/docgen-skins 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/sonar-project.properties +4 -4
- package/.github/workflows/ci.yml +23 -18
- package/.github/workflows/release.yml +47 -45
- package/Readme.md +6 -6
- package/bin/index.d.ts +15 -0
- package/bin/index.js +277 -0
- package/bin/index.js.map +1 -0
- package/bin/models/json/JSONRun.d.ts +7 -0
- package/bin/models/json/JSONRun.js +84 -0
- package/bin/models/json/JSONRun.js.map +1 -0
- package/bin/models/json/default.d.ts +3 -0
- package/bin/models/json/default.js +25 -0
- package/bin/models/json/default.js.map +1 -0
- package/bin/models/json/html/JSONHtml.d.ts +6 -0
- package/bin/models/json/html/JSONHtml.js +13 -0
- package/bin/models/json/html/JSONHtml.js.map +1 -0
- package/bin/models/json/paragraph/JSONParagraph.d.ts +9 -0
- package/bin/models/json/paragraph/JSONParagraph.js +62 -0
- package/bin/models/json/paragraph/JSONParagraph.js.map +1 -0
- package/bin/models/json/paragraph/JSONRichTextParagraph.d.ts +9 -0
- package/bin/models/json/paragraph/JSONRichTextParagraph.js +72 -0
- package/bin/models/json/paragraph/JSONRichTextParagraph.js.map +1 -0
- package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.d.ts +10 -0
- package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.js +76 -0
- package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.js.map +1 -0
- package/bin/models/json/table/JSONTable.d.ts +9 -0
- package/bin/models/json/table/JSONTable.js +60 -0
- package/bin/models/json/table/JSONTable.js.map +1 -0
- package/bin/models/json/table/JSONTableCell.d.ts +8 -0
- package/bin/models/json/table/JSONTableCell.js +105 -0
- package/bin/models/json/table/JSONTableCell.js.map +1 -0
- package/bin/models/json/table/JSONTableRow.d.ts +7 -0
- package/bin/models/json/table/JSONTableRow.js +27 -0
- package/bin/models/json/table/JSONTableRow.js.map +1 -0
- package/bin/models/json/wordJsonModels.d.ts +97 -0
- package/bin/models/json/wordJsonModels.js +3 -0
- package/bin/models/json/wordJsonModels.js.map +1 -0
- package/bin/services/logger.d.ts +3 -0
- package/bin/services/logger.js +46 -0
- package/bin/services/logger.js.map +1 -0
- package/bin/snippets/free-runs.d.ts +1 -0
- package/bin/snippets/free-runs.js +58 -0
- package/bin/snippets/free-runs.js.map +1 -0
- package/bin/test/skins.test.d.ts +1 -0
- package/bin/test/skins.test.js +116 -0
- package/bin/test/skins.test.js.map +1 -0
- package/package.json +46 -46
- package/samples/document-skins-examples/document-attchament-table.json +25 -25
- package/samples/document-skins-examples/documentExample.json +66 -66
- package/samples/document-skins-examples/paragraphExample.json +16 -16
- package/samples/document-skins-examples/tableExample.json +29 -29
- package/src/index.ts +338 -401
- package/src/models/json/JSONRun.ts +80 -80
- package/src/models/json/default.ts +23 -23
- package/src/models/json/html/JSONHtml.ts +13 -13
- package/src/models/json/paragraph/JSONParagraph.ts +76 -76
- package/src/models/json/paragraph/JSONRichTextParagraph.ts +84 -84
- package/src/models/json/paragraph/JSONTestSuiteHeaderParagraph.ts +94 -94
- package/src/models/json/table/JSONTable.ts +74 -74
- package/src/models/json/table/JSONTableCell.ts +117 -117
- package/src/models/json/table/JSONTableRow.ts +34 -34
- package/src/models/json/wordJsonModels.ts +97 -97
- package/src/services/logger.ts +26 -26
- package/src/snippets/free-runs.ts +53 -53
- package/src/test/skins.test.ts +171 -171
- package/tsconfig.json +61 -61
|
@@ -1,80 +1,80 @@
|
|
|
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
|
-
|
|
6
|
-
const replaceBr = ({ tag, deleteFrom, deleteTo, rangesArr }) => {
|
|
7
|
-
if (tag.name === `br`) {
|
|
8
|
-
rangesArr.push(deleteFrom, deleteTo, "\n");
|
|
9
|
-
} else {
|
|
10
|
-
rangesArr.push(deleteFrom, deleteTo, " ");
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default class JSONRun {
|
|
15
|
-
runs: Run[];
|
|
16
|
-
|
|
17
|
-
constructor(value: string, styles: StyleOptions, fieldtype?: string) {
|
|
18
|
-
this.runs = this.generateJsonRun(value, styles, fieldtype);
|
|
19
|
-
} //constructor
|
|
20
|
-
|
|
21
|
-
generateJsonRun(value: string, style: StyleOptions, fieldtype?: string): Run[] {
|
|
22
|
-
let runs: Run[] = [];
|
|
23
|
-
let rowArray;
|
|
24
|
-
try {
|
|
25
|
-
rowArray = value.split("\n");
|
|
26
|
-
//try iterating the array
|
|
27
|
-
rowArray.forEach((text, i) => {
|
|
28
|
-
let run: Run = defaultJsonRun;
|
|
29
|
-
if (fieldtype !== "SuiteHeaderParagraphTitle") {
|
|
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;
|
|
47
|
-
}
|
|
48
|
-
if (rowArray.length - 1 == i) {
|
|
49
|
-
run.InsertLineBreak = style.InsertLineBreak;
|
|
50
|
-
}
|
|
51
|
-
run.InsertSpace = style.InsertSpace;
|
|
52
|
-
runs.push(JSON.parse(JSON.stringify(run)));
|
|
53
|
-
});
|
|
54
|
-
} catch (e) {
|
|
55
|
-
logger.silly(`${value} - cannot be splitted`);
|
|
56
|
-
runs[0] = defaultJsonRun;
|
|
57
|
-
runs[0].text = value
|
|
58
|
-
? `${striphtml(value.toString(), { cb: replaceBr })}`
|
|
59
|
-
: ``;
|
|
60
|
-
runs[0].Bold = style.isBold;
|
|
61
|
-
runs[0].Italic = style.IsItalic;
|
|
62
|
-
runs[0].Underline = style.IsUnderline;
|
|
63
|
-
runs[0].Size = style.Size;
|
|
64
|
-
if (runs[0].Uri === "") {
|
|
65
|
-
runs[0].Uri = null;
|
|
66
|
-
} else {
|
|
67
|
-
runs[0].Uri = style.Uri;
|
|
68
|
-
}
|
|
69
|
-
runs[0].Font = style.Font;
|
|
70
|
-
runs[0].InsertLineBreak = style.InsertLineBreak;
|
|
71
|
-
runs[0].InsertSpace = style.InsertSpace;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return runs;
|
|
75
|
-
} //generateJsonRun
|
|
76
|
-
|
|
77
|
-
getRun(): Run[] {
|
|
78
|
-
return this.runs;
|
|
79
|
-
}
|
|
80
|
-
} //class
|
|
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
|
+
|
|
6
|
+
const replaceBr = ({ tag, deleteFrom, deleteTo, rangesArr }) => {
|
|
7
|
+
if (tag.name === `br`) {
|
|
8
|
+
rangesArr.push(deleteFrom, deleteTo, "\n");
|
|
9
|
+
} else {
|
|
10
|
+
rangesArr.push(deleteFrom, deleteTo, " ");
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default class JSONRun {
|
|
15
|
+
runs: Run[];
|
|
16
|
+
|
|
17
|
+
constructor(value: string, styles: StyleOptions, fieldtype?: string) {
|
|
18
|
+
this.runs = this.generateJsonRun(value, styles, fieldtype);
|
|
19
|
+
} //constructor
|
|
20
|
+
|
|
21
|
+
generateJsonRun(value: string, style: StyleOptions, fieldtype?: string): Run[] {
|
|
22
|
+
let runs: Run[] = [];
|
|
23
|
+
let rowArray;
|
|
24
|
+
try {
|
|
25
|
+
rowArray = value.split("\n");
|
|
26
|
+
//try iterating the array
|
|
27
|
+
rowArray.forEach((text, i) => {
|
|
28
|
+
let run: Run = defaultJsonRun;
|
|
29
|
+
if (fieldtype !== "SuiteHeaderParagraphTitle") {
|
|
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;
|
|
47
|
+
}
|
|
48
|
+
if (rowArray.length - 1 == i) {
|
|
49
|
+
run.InsertLineBreak = style.InsertLineBreak;
|
|
50
|
+
}
|
|
51
|
+
run.InsertSpace = style.InsertSpace;
|
|
52
|
+
runs.push(JSON.parse(JSON.stringify(run)));
|
|
53
|
+
});
|
|
54
|
+
} catch (e) {
|
|
55
|
+
logger.silly(`${value} - cannot be splitted`);
|
|
56
|
+
runs[0] = defaultJsonRun;
|
|
57
|
+
runs[0].text = value
|
|
58
|
+
? `${striphtml(value.toString(), { cb: replaceBr })}`
|
|
59
|
+
: ``;
|
|
60
|
+
runs[0].Bold = style.isBold;
|
|
61
|
+
runs[0].Italic = style.IsItalic;
|
|
62
|
+
runs[0].Underline = style.IsUnderline;
|
|
63
|
+
runs[0].Size = style.Size;
|
|
64
|
+
if (runs[0].Uri === "") {
|
|
65
|
+
runs[0].Uri = null;
|
|
66
|
+
} else {
|
|
67
|
+
runs[0].Uri = style.Uri;
|
|
68
|
+
}
|
|
69
|
+
runs[0].Font = style.Font;
|
|
70
|
+
runs[0].InsertLineBreak = style.InsertLineBreak;
|
|
71
|
+
runs[0].InsertSpace = style.InsertSpace;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return runs;
|
|
75
|
+
} //generateJsonRun
|
|
76
|
+
|
|
77
|
+
getRun(): Run[] {
|
|
78
|
+
return this.runs;
|
|
79
|
+
}
|
|
80
|
+
} //class
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Run, StyleOptions } from "./wordJsonModels";
|
|
2
|
-
|
|
3
|
-
export let defaultJsonRun: Run = {
|
|
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
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export let DescriptionandProcedureStyle: StyleOptions = {
|
|
16
|
-
isBold: true,
|
|
17
|
-
IsItalic: false,
|
|
18
|
-
IsUnderline: true,
|
|
19
|
-
Size: 12,
|
|
20
|
-
Uri: null,
|
|
21
|
-
Font: "Arial",
|
|
22
|
-
InsertLineBreak: false,
|
|
23
|
-
InsertSpace: false,
|
|
1
|
+
import { Run, StyleOptions } from "./wordJsonModels";
|
|
2
|
+
|
|
3
|
+
export let defaultJsonRun: Run = {
|
|
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
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export let DescriptionandProcedureStyle: StyleOptions = {
|
|
16
|
+
isBold: true,
|
|
17
|
+
IsItalic: false,
|
|
18
|
+
IsUnderline: true,
|
|
19
|
+
Size: 12,
|
|
20
|
+
Uri: null,
|
|
21
|
+
Font: "Arial",
|
|
22
|
+
InsertLineBreak: false,
|
|
23
|
+
InsertSpace: false,
|
|
24
24
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { JsonHtml } from "../wordJsonModels";
|
|
2
|
-
import JSONRun from "../JSONRun";
|
|
3
|
-
|
|
4
|
-
export default class JSONHtml {
|
|
5
|
-
htmlString: string = "";
|
|
6
|
-
constructor(htmlString: string) {
|
|
7
|
-
this.htmlString = htmlString;
|
|
8
|
-
} //constructor
|
|
9
|
-
|
|
10
|
-
getJSONHtml(): JsonHtml {
|
|
11
|
-
return { type: "html", Html: this.htmlString };
|
|
12
|
-
} //getJSONTable
|
|
13
|
-
} //class
|
|
1
|
+
import { JsonHtml } from "../wordJsonModels";
|
|
2
|
+
import JSONRun from "../JSONRun";
|
|
3
|
+
|
|
4
|
+
export default class JSONHtml {
|
|
5
|
+
htmlString: string = "";
|
|
6
|
+
constructor(htmlString: string) {
|
|
7
|
+
this.htmlString = htmlString;
|
|
8
|
+
} //constructor
|
|
9
|
+
|
|
10
|
+
getJSONHtml(): JsonHtml {
|
|
11
|
+
return { type: "html", Html: this.htmlString };
|
|
12
|
+
} //getJSONTable
|
|
13
|
+
} //class
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Paragraph,
|
|
3
|
-
Run,
|
|
4
|
-
WIData,
|
|
5
|
-
WIProperty,
|
|
6
|
-
StyleOptions,
|
|
7
|
-
} from "../wordJsonModels";
|
|
8
|
-
import JSONRun from "../JSONRun";
|
|
9
|
-
|
|
10
|
-
export default class JSONParagraph {
|
|
11
|
-
paragraphStyles: StyleOptions;
|
|
12
|
-
paragraphTemplate: Paragraph;
|
|
13
|
-
wiId: number;
|
|
14
|
-
constructor(
|
|
15
|
-
field: WIProperty,
|
|
16
|
-
paragraphStyles: StyleOptions,
|
|
17
|
-
wiId: number,
|
|
18
|
-
headingLevel: number
|
|
19
|
-
) {
|
|
20
|
-
this.paragraphStyles = paragraphStyles;
|
|
21
|
-
this.wiId = wiId;
|
|
22
|
-
this.paragraphTemplate = {
|
|
23
|
-
type: "paragraph",
|
|
24
|
-
runs: this.generateJsonParagraphRun(field, this.paragraphStyles),
|
|
25
|
-
};
|
|
26
|
-
if (headingLevel && field.name === "Title: ") {
|
|
27
|
-
this.paragraphTemplate.headingLevel = headingLevel;
|
|
28
|
-
} else {
|
|
29
|
-
this.paragraphTemplate.headingLevel = 0;
|
|
30
|
-
}
|
|
31
|
-
} //constructor
|
|
32
|
-
|
|
33
|
-
generateJsonParagraphRun(field: WIProperty, paragraphStyles): Run[] {
|
|
34
|
-
let jsonRun: JSONRun;
|
|
35
|
-
let runs: Run[] = [];
|
|
36
|
-
let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
|
|
37
|
-
|
|
38
|
-
titleStyle.isBold = false;
|
|
39
|
-
titleStyle.IsUnderline = true;
|
|
40
|
-
titleStyle.InsertSpace = true;
|
|
41
|
-
titleStyle.InsertLineBreak = false;
|
|
42
|
-
//adds ':' to field titles
|
|
43
|
-
if (field.name !== "") {
|
|
44
|
-
field.name += ": ";
|
|
45
|
-
}
|
|
46
|
-
//exclude titles for fields that only show values
|
|
47
|
-
if (
|
|
48
|
-
field.name !== "Title: " &&
|
|
49
|
-
field.name !== "ID: " &&
|
|
50
|
-
field.name !== "Description: " &&
|
|
51
|
-
field.name !== "text: "
|
|
52
|
-
) {
|
|
53
|
-
paragraphStyles.Uri = field.url;
|
|
54
|
-
jsonRun = new JSONRun(field.name, titleStyle);
|
|
55
|
-
runs = [...runs, ...jsonRun.runs];
|
|
56
|
-
|
|
57
|
-
paragraphStyles.InsertLineBreak = false;
|
|
58
|
-
} //end if
|
|
59
|
-
|
|
60
|
-
if (field.name === "Title: ") {
|
|
61
|
-
paragraphStyles.Uri = field.url;
|
|
62
|
-
paragraphStyles.InsertLineBreak = false;
|
|
63
|
-
jsonRun = new JSONRun(field.value, paragraphStyles);
|
|
64
|
-
runs = [...runs, ...jsonRun.runs];
|
|
65
|
-
} else {
|
|
66
|
-
paragraphStyles.Uri = field.url;
|
|
67
|
-
jsonRun = new JSONRun(field.value, paragraphStyles);
|
|
68
|
-
runs = [...runs, ...jsonRun.runs];
|
|
69
|
-
}
|
|
70
|
-
return runs;
|
|
71
|
-
} //generateJsonParagraph
|
|
72
|
-
|
|
73
|
-
getJSONParagraph(): Paragraph {
|
|
74
|
-
return this.paragraphTemplate;
|
|
75
|
-
} //getJSONTable
|
|
76
|
-
} //class
|
|
1
|
+
import {
|
|
2
|
+
Paragraph,
|
|
3
|
+
Run,
|
|
4
|
+
WIData,
|
|
5
|
+
WIProperty,
|
|
6
|
+
StyleOptions,
|
|
7
|
+
} from "../wordJsonModels";
|
|
8
|
+
import JSONRun from "../JSONRun";
|
|
9
|
+
|
|
10
|
+
export default class JSONParagraph {
|
|
11
|
+
paragraphStyles: StyleOptions;
|
|
12
|
+
paragraphTemplate: Paragraph;
|
|
13
|
+
wiId: number;
|
|
14
|
+
constructor(
|
|
15
|
+
field: WIProperty,
|
|
16
|
+
paragraphStyles: StyleOptions,
|
|
17
|
+
wiId: number,
|
|
18
|
+
headingLevel: number
|
|
19
|
+
) {
|
|
20
|
+
this.paragraphStyles = paragraphStyles;
|
|
21
|
+
this.wiId = wiId;
|
|
22
|
+
this.paragraphTemplate = {
|
|
23
|
+
type: "paragraph",
|
|
24
|
+
runs: this.generateJsonParagraphRun(field, this.paragraphStyles),
|
|
25
|
+
};
|
|
26
|
+
if (headingLevel && field.name === "Title: ") {
|
|
27
|
+
this.paragraphTemplate.headingLevel = headingLevel;
|
|
28
|
+
} else {
|
|
29
|
+
this.paragraphTemplate.headingLevel = 0;
|
|
30
|
+
}
|
|
31
|
+
} //constructor
|
|
32
|
+
|
|
33
|
+
generateJsonParagraphRun(field: WIProperty, paragraphStyles): Run[] {
|
|
34
|
+
let jsonRun: JSONRun;
|
|
35
|
+
let runs: Run[] = [];
|
|
36
|
+
let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
|
|
37
|
+
|
|
38
|
+
titleStyle.isBold = false;
|
|
39
|
+
titleStyle.IsUnderline = true;
|
|
40
|
+
titleStyle.InsertSpace = true;
|
|
41
|
+
titleStyle.InsertLineBreak = false;
|
|
42
|
+
//adds ':' to field titles
|
|
43
|
+
if (field.name !== "") {
|
|
44
|
+
field.name += ": ";
|
|
45
|
+
}
|
|
46
|
+
//exclude titles for fields that only show values
|
|
47
|
+
if (
|
|
48
|
+
field.name !== "Title: " &&
|
|
49
|
+
field.name !== "ID: " &&
|
|
50
|
+
field.name !== "Description: " &&
|
|
51
|
+
field.name !== "text: "
|
|
52
|
+
) {
|
|
53
|
+
paragraphStyles.Uri = field.url;
|
|
54
|
+
jsonRun = new JSONRun(field.name, titleStyle);
|
|
55
|
+
runs = [...runs, ...jsonRun.runs];
|
|
56
|
+
|
|
57
|
+
paragraphStyles.InsertLineBreak = false;
|
|
58
|
+
} //end if
|
|
59
|
+
|
|
60
|
+
if (field.name === "Title: ") {
|
|
61
|
+
paragraphStyles.Uri = field.url;
|
|
62
|
+
paragraphStyles.InsertLineBreak = false;
|
|
63
|
+
jsonRun = new JSONRun(field.value, paragraphStyles);
|
|
64
|
+
runs = [...runs, ...jsonRun.runs];
|
|
65
|
+
} else {
|
|
66
|
+
paragraphStyles.Uri = field.url;
|
|
67
|
+
jsonRun = new JSONRun(field.value, paragraphStyles);
|
|
68
|
+
runs = [...runs, ...jsonRun.runs];
|
|
69
|
+
}
|
|
70
|
+
return runs;
|
|
71
|
+
} //generateJsonParagraph
|
|
72
|
+
|
|
73
|
+
getJSONParagraph(): Paragraph {
|
|
74
|
+
return this.paragraphTemplate;
|
|
75
|
+
} //getJSONTable
|
|
76
|
+
} //class
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { Run, WIProperty, StyleOptions } from "../wordJsonModels";
|
|
2
|
-
import JSONHtml from "../html/JSONHtml";
|
|
3
|
-
import JSONParagraph from "./JSONParagraph";
|
|
4
|
-
import JSONTable from "../table/JSONTable";
|
|
5
|
-
import logger from "../../../services/logger";
|
|
6
|
-
|
|
7
|
-
export default class JSONRichTextParagraph {
|
|
8
|
-
paragraphStyles: StyleOptions;
|
|
9
|
-
paragraphTemplate: any;
|
|
10
|
-
wiId: number;
|
|
11
|
-
constructor(
|
|
12
|
-
field: WIProperty,
|
|
13
|
-
paragraphStyles: StyleOptions,
|
|
14
|
-
wiId: number,
|
|
15
|
-
headingLevel: number
|
|
16
|
-
) {
|
|
17
|
-
this.paragraphStyles = paragraphStyles;
|
|
18
|
-
this.wiId = wiId;
|
|
19
|
-
this.paragraphTemplate = this.generateJsonRichTextParagraphs(
|
|
20
|
-
field,
|
|
21
|
-
this.paragraphStyles
|
|
22
|
-
);
|
|
23
|
-
if (headingLevel && field.name === "Title: ") {
|
|
24
|
-
this.paragraphTemplate.headingLevel = headingLevel;
|
|
25
|
-
} else {
|
|
26
|
-
this.paragraphTemplate.headingLevel = 0;
|
|
27
|
-
}
|
|
28
|
-
} //constructor
|
|
29
|
-
|
|
30
|
-
generateJsonRichTextParagraphs(field: WIProperty, paragraphStyles): Run[] {
|
|
31
|
-
let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
|
|
32
|
-
|
|
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(
|
|
51
|
-
richTextField,
|
|
52
|
-
paragraphStyles,
|
|
53
|
-
0,
|
|
54
|
-
0
|
|
55
|
-
);
|
|
56
|
-
richTextSkin.push(paragraphSkin.getJSONParagraph());
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
break;
|
|
60
|
-
case "picture":
|
|
61
|
-
richTextSkin.push({
|
|
62
|
-
type: "picture",
|
|
63
|
-
Path: content.data,
|
|
64
|
-
});
|
|
65
|
-
break;
|
|
66
|
-
case "table":
|
|
67
|
-
if (content.data) {
|
|
68
|
-
let tableSkin = new JSONTable(content.data, paragraphStyles, 0);
|
|
69
|
-
richTextSkin.push(tableSkin.getJSONTable());
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return richTextSkin;
|
|
75
|
-
} catch (e) {
|
|
76
|
-
logger.warn(e);
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
} //generateJsonRichTextParagraphs
|
|
80
|
-
|
|
81
|
-
getJSONRichTextParagraph(): any[] {
|
|
82
|
-
return this.paragraphTemplate;
|
|
83
|
-
} //getJSONTable
|
|
84
|
-
} //class
|
|
1
|
+
import { Run, WIProperty, StyleOptions } from "../wordJsonModels";
|
|
2
|
+
import JSONHtml from "../html/JSONHtml";
|
|
3
|
+
import JSONParagraph from "./JSONParagraph";
|
|
4
|
+
import JSONTable from "../table/JSONTable";
|
|
5
|
+
import logger from "../../../services/logger";
|
|
6
|
+
|
|
7
|
+
export default class JSONRichTextParagraph {
|
|
8
|
+
paragraphStyles: StyleOptions;
|
|
9
|
+
paragraphTemplate: any;
|
|
10
|
+
wiId: number;
|
|
11
|
+
constructor(
|
|
12
|
+
field: WIProperty,
|
|
13
|
+
paragraphStyles: StyleOptions,
|
|
14
|
+
wiId: number,
|
|
15
|
+
headingLevel: number
|
|
16
|
+
) {
|
|
17
|
+
this.paragraphStyles = paragraphStyles;
|
|
18
|
+
this.wiId = wiId;
|
|
19
|
+
this.paragraphTemplate = this.generateJsonRichTextParagraphs(
|
|
20
|
+
field,
|
|
21
|
+
this.paragraphStyles
|
|
22
|
+
);
|
|
23
|
+
if (headingLevel && field.name === "Title: ") {
|
|
24
|
+
this.paragraphTemplate.headingLevel = headingLevel;
|
|
25
|
+
} else {
|
|
26
|
+
this.paragraphTemplate.headingLevel = 0;
|
|
27
|
+
}
|
|
28
|
+
} //constructor
|
|
29
|
+
|
|
30
|
+
generateJsonRichTextParagraphs(field: WIProperty, paragraphStyles): Run[] {
|
|
31
|
+
let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
|
|
32
|
+
|
|
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(
|
|
51
|
+
richTextField,
|
|
52
|
+
paragraphStyles,
|
|
53
|
+
0,
|
|
54
|
+
0
|
|
55
|
+
);
|
|
56
|
+
richTextSkin.push(paragraphSkin.getJSONParagraph());
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
case "picture":
|
|
61
|
+
richTextSkin.push({
|
|
62
|
+
type: "picture",
|
|
63
|
+
Path: content.data,
|
|
64
|
+
});
|
|
65
|
+
break;
|
|
66
|
+
case "table":
|
|
67
|
+
if (content.data) {
|
|
68
|
+
let tableSkin = new JSONTable(content.data, paragraphStyles, 0);
|
|
69
|
+
richTextSkin.push(tableSkin.getJSONTable());
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return richTextSkin;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
logger.warn(e);
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
} //generateJsonRichTextParagraphs
|
|
80
|
+
|
|
81
|
+
getJSONRichTextParagraph(): any[] {
|
|
82
|
+
return this.paragraphTemplate;
|
|
83
|
+
} //getJSONTable
|
|
84
|
+
} //class
|