@jxsuite/parser 0.8.0 → 0.9.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/html-to-jx.js +28 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jxsuite/parser",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Jx markdown parser and external class integration",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/html-to-jx.js CHANGED
@@ -42,7 +42,9 @@ function convertHastNode(node) {
42
42
  const el = { tagName: node.tagName };
43
43
 
44
44
  if (node.properties && Object.keys(node.properties).length > 0) {
45
- el.attributes = hastPropsToAttributes(node.properties);
45
+ const { style, attrs } = hastPropsToJx(node.properties);
46
+ if (Object.keys(attrs).length > 0) el.attributes = attrs;
47
+ if (Object.keys(style).length > 0) el.style = style;
46
48
  }
47
49
 
48
50
  const kids = node.children ? convertHastChildren(node.children) : [];
@@ -61,17 +63,25 @@ function convertHastNode(node) {
61
63
 
62
64
  /**
63
65
  * @param {Record<string, any>} properties
64
- * @returns {Record<string, string>}
66
+ * @returns {{ style: Record<string, string>; attrs: Record<string, string> }}
65
67
  */
66
- function hastPropsToAttributes(properties) {
68
+ function hastPropsToJx(properties) {
67
69
  /** @type {Record<string, string>} */
68
70
  const attrs = {};
71
+ /** @type {Record<string, string>} */
72
+ const style = {};
73
+
69
74
  for (const [key, value] of Object.entries(properties)) {
70
75
  if (value === false || value === undefined || value === null) continue;
71
76
 
72
77
  const info = find(htmlInfo, key);
73
78
  const name = info.attribute;
74
79
 
80
+ if (name === "style" && typeof value === "string") {
81
+ parseInlineStyle(value, style);
82
+ continue;
83
+ }
84
+
75
85
  if (value === true) {
76
86
  attrs[name] = "";
77
87
  } else if (Array.isArray(value)) {
@@ -80,5 +90,19 @@ function hastPropsToAttributes(properties) {
80
90
  attrs[name] = String(value);
81
91
  }
82
92
  }
83
- return attrs;
93
+ return { style, attrs };
94
+ }
95
+
96
+ /**
97
+ * @param {string} styleStr
98
+ * @param {Record<string, string>} out
99
+ */
100
+ function parseInlineStyle(styleStr, out) {
101
+ for (const decl of styleStr.split(";")) {
102
+ const colon = decl.indexOf(":");
103
+ if (colon === -1) continue;
104
+ const prop = decl.slice(0, colon).trim();
105
+ const val = decl.slice(colon + 1).trim();
106
+ if (prop && val) out[prop] = val;
107
+ }
84
108
  }