@contrail/document-generation 1.0.24 → 1.0.26

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.
@@ -2,5 +2,8 @@ import { DocumentElement, StyleDefinition } from "@contrail/documents";
2
2
  export declare class DocumentTextElementUtil {
3
3
  static generateTextElement(textValue: any, options: any, applyInlineFormatting?: boolean): DocumentElement;
4
4
  static applyInLineStyling(text: any, style: StyleDefinition): any;
5
- static applyBold(text: any): void;
5
+ static extractStyleFromInline(text: string): StyleDefinition;
6
+ static extractFontSizeFromHTML(text: any): number;
7
+ static extractColorFromHTML(text: any): string;
8
+ static extractTextDecorationFromHTML(text: any): string;
6
9
  }
@@ -52,8 +52,52 @@ class DocumentTextElementUtil {
52
52
  formattedText = `<p>${formattedText}</p>`;
53
53
  return formattedText;
54
54
  }
55
- static applyBold(text) {
56
- return;
55
+ static extractStyleFromInline(text) {
56
+ if (!text) {
57
+ return null;
58
+ }
59
+ const style = { font: {}, text: {} };
60
+ if (text.indexOf('<strong>') > -1 || text.indexOf("bold") > -1) {
61
+ style.font.weight = 'bold';
62
+ }
63
+ const fontSize = this.extractFontSizeFromHTML(text);
64
+ if (fontSize) {
65
+ style.font.size = fontSize;
66
+ }
67
+ const color = this.extractColorFromHTML(text);
68
+ if (color) {
69
+ style.color = color;
70
+ }
71
+ const decoration = this.extractTextDecorationFromHTML(text);
72
+ if (decoration) {
73
+ style.text.decoration = decoration;
74
+ }
75
+ return style;
76
+ }
77
+ static extractFontSizeFromHTML(text) {
78
+ let regex = /font-size: (.*?)pt;/;
79
+ let match = text.match(regex);
80
+ if ((match === null || match === void 0 ? void 0 : match.length) && !isNaN(parseInt(match[1]))) {
81
+ return parseInt(match[1]);
82
+ }
83
+ }
84
+ static extractColorFromHTML(text) {
85
+ let regex = /color: (.*?);/;
86
+ let match = text.match(regex);
87
+ if (match === null || match === void 0 ? void 0 : match.length) {
88
+ let color = match[1];
89
+ color = color.replace(/['"]+/g, '');
90
+ return color;
91
+ }
92
+ }
93
+ static extractTextDecorationFromHTML(text) {
94
+ let regex = /text-decoration: (.*?);/;
95
+ let match = text.match(regex);
96
+ if (match === null || match === void 0 ? void 0 : match.length) {
97
+ let decoration = match[1];
98
+ decoration = decoration.replace(/['"]+/g, '');
99
+ return decoration;
100
+ }
57
101
  }
58
102
  }
59
103
  exports.DocumentTextElementUtil = DocumentTextElementUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-generation",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Utilities for automatic generation of documents.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",