@jxsuite/parser 0.7.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.
- package/package.json +2 -2
- package/src/html-to-jx.js +28 -4
- package/src/transpile.js +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jxsuite/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Jx markdown parser and external class integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@happy-dom/global-registrator": "^20.9.0",
|
|
44
|
-
"@jxsuite/runtime": "^0.
|
|
44
|
+
"@jxsuite/runtime": "^0.7.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
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
|
-
|
|
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
|
|
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
|
}
|
package/src/transpile.js
CHANGED
|
@@ -586,7 +586,9 @@ export function transpileJxMarkdown(source) {
|
|
|
586
586
|
|
|
587
587
|
for (const node of bodyNodes) {
|
|
588
588
|
const converted = mdastNodeToJx(node);
|
|
589
|
-
if (converted
|
|
589
|
+
if (converted == null) continue;
|
|
590
|
+
if (Array.isArray(converted)) children.push(...converted);
|
|
591
|
+
else children.push(converted);
|
|
590
592
|
}
|
|
591
593
|
|
|
592
594
|
if (children.length > 0) {
|