@examind/block-sdk 0.1.11 → 0.1.13
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/dist/index.js +42 -51
- package/dist/index.mjs +42 -51
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1724,70 +1724,61 @@ var import_node_html_parser20 = require("node-html-parser");
|
|
|
1724
1724
|
var TextNode = import_node_html_parser20.parse.TextNode;
|
|
1725
1725
|
var SpanNodeHandler = class extends NodeHandler2 {
|
|
1726
1726
|
processNode(node) {
|
|
1727
|
-
if (!(node instanceof import_node_html_parser20.HTMLElement)
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
const styleAttr = node.getAttribute("style");
|
|
1731
|
-
if (!styleAttr) return null;
|
|
1727
|
+
if (!(node instanceof import_node_html_parser20.HTMLElement) || node.tagName !== "SPAN")
|
|
1728
|
+
return null;
|
|
1729
|
+
const styleAttr = node.getAttribute("style") || "";
|
|
1732
1730
|
if (node.childNodes.length === 1 && node.childNodes[0] instanceof TextNode) {
|
|
1733
|
-
|
|
1734
|
-
return {
|
|
1735
|
-
detail: 0,
|
|
1736
|
-
format: 0,
|
|
1737
|
-
mode: "normal",
|
|
1738
|
-
style: styleAttr,
|
|
1739
|
-
text: textContent2,
|
|
1740
|
-
type: "text",
|
|
1741
|
-
version: 1
|
|
1742
|
-
};
|
|
1731
|
+
return this.createTextNode(node.text, styleAttr);
|
|
1743
1732
|
}
|
|
1744
|
-
|
|
1733
|
+
const results = [];
|
|
1734
|
+
const textNodes = [];
|
|
1745
1735
|
for (const childNode of node.childNodes) {
|
|
1746
|
-
const
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
if (!childResult) {
|
|
1751
|
-
childResult = {
|
|
1752
|
-
...textNode,
|
|
1753
|
-
style: this.mergeStyles(textNode.style, styleAttr)
|
|
1754
|
-
};
|
|
1736
|
+
for (const child of traverse2(childNode)) {
|
|
1737
|
+
if (child.type === "text") {
|
|
1738
|
+
const textNode = child;
|
|
1739
|
+
textNodes.push(textNode);
|
|
1755
1740
|
} else {
|
|
1756
|
-
|
|
1757
|
-
childResult.format |= textNode.format || 0;
|
|
1758
|
-
if (textNode.style) {
|
|
1759
|
-
childResult.style = this.mergeStyles(
|
|
1760
|
-
childResult.style,
|
|
1761
|
-
textNode.style
|
|
1762
|
-
);
|
|
1763
|
-
}
|
|
1741
|
+
results.push(child);
|
|
1764
1742
|
}
|
|
1765
1743
|
}
|
|
1766
1744
|
}
|
|
1767
|
-
if (
|
|
1768
|
-
|
|
1769
|
-
|
|
1745
|
+
if (textNodes.length > 0) {
|
|
1746
|
+
const mergedTextNode = this.mergeTextNodes(
|
|
1747
|
+
textNodes,
|
|
1770
1748
|
styleAttr
|
|
1771
1749
|
);
|
|
1772
|
-
|
|
1750
|
+
results.push(mergedTextNode);
|
|
1751
|
+
} else if (node.text.trim()) {
|
|
1752
|
+
results.push(this.createTextNode(node.text, styleAttr));
|
|
1773
1753
|
}
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
};
|
|
1754
|
+
return results;
|
|
1755
|
+
}
|
|
1756
|
+
mergeTextNodes(textNodes, spanStyle) {
|
|
1757
|
+
const result = { ...textNodes[0] };
|
|
1758
|
+
result.style = this.mergeStyles(result.style, spanStyle);
|
|
1759
|
+
for (let i = 1; i < textNodes.length; i++) {
|
|
1760
|
+
const node = textNodes[i];
|
|
1761
|
+
result.text += node.text;
|
|
1762
|
+
result.format |= node.format || 0;
|
|
1763
|
+
result.style = this.mergeStyles(result.style, node.style);
|
|
1785
1764
|
}
|
|
1786
|
-
return
|
|
1765
|
+
return result;
|
|
1766
|
+
}
|
|
1767
|
+
createTextNode(text, style) {
|
|
1768
|
+
return {
|
|
1769
|
+
detail: 0,
|
|
1770
|
+
format: 0,
|
|
1771
|
+
mode: "normal",
|
|
1772
|
+
style,
|
|
1773
|
+
text,
|
|
1774
|
+
type: "text",
|
|
1775
|
+
version: 1
|
|
1776
|
+
};
|
|
1787
1777
|
}
|
|
1788
1778
|
mergeStyles(existingStyle, newStyle) {
|
|
1789
|
-
if (!existingStyle) return
|
|
1790
|
-
if (!
|
|
1779
|
+
if (!existingStyle && !newStyle) return "";
|
|
1780
|
+
if (!existingStyle) return newStyle ?? "";
|
|
1781
|
+
if (!newStyle) return existingStyle ?? "";
|
|
1791
1782
|
return `${existingStyle};${newStyle}`.replace(/;;/g, ";").replace(/^;/, "").replace(/;$/, "");
|
|
1792
1783
|
}
|
|
1793
1784
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1697,70 +1697,61 @@ import { HTMLElement as HTMLElement20, parse } from "node-html-parser";
|
|
|
1697
1697
|
var TextNode = parse.TextNode;
|
|
1698
1698
|
var SpanNodeHandler = class extends NodeHandler2 {
|
|
1699
1699
|
processNode(node) {
|
|
1700
|
-
if (!(node instanceof HTMLElement20)
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
const styleAttr = node.getAttribute("style");
|
|
1704
|
-
if (!styleAttr) return null;
|
|
1700
|
+
if (!(node instanceof HTMLElement20) || node.tagName !== "SPAN")
|
|
1701
|
+
return null;
|
|
1702
|
+
const styleAttr = node.getAttribute("style") || "";
|
|
1705
1703
|
if (node.childNodes.length === 1 && node.childNodes[0] instanceof TextNode) {
|
|
1706
|
-
|
|
1707
|
-
return {
|
|
1708
|
-
detail: 0,
|
|
1709
|
-
format: 0,
|
|
1710
|
-
mode: "normal",
|
|
1711
|
-
style: styleAttr,
|
|
1712
|
-
text: textContent2,
|
|
1713
|
-
type: "text",
|
|
1714
|
-
version: 1
|
|
1715
|
-
};
|
|
1704
|
+
return this.createTextNode(node.text, styleAttr);
|
|
1716
1705
|
}
|
|
1717
|
-
|
|
1706
|
+
const results = [];
|
|
1707
|
+
const textNodes = [];
|
|
1718
1708
|
for (const childNode of node.childNodes) {
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
if (!childResult) {
|
|
1724
|
-
childResult = {
|
|
1725
|
-
...textNode,
|
|
1726
|
-
style: this.mergeStyles(textNode.style, styleAttr)
|
|
1727
|
-
};
|
|
1709
|
+
for (const child of traverse2(childNode)) {
|
|
1710
|
+
if (child.type === "text") {
|
|
1711
|
+
const textNode = child;
|
|
1712
|
+
textNodes.push(textNode);
|
|
1728
1713
|
} else {
|
|
1729
|
-
|
|
1730
|
-
childResult.format |= textNode.format || 0;
|
|
1731
|
-
if (textNode.style) {
|
|
1732
|
-
childResult.style = this.mergeStyles(
|
|
1733
|
-
childResult.style,
|
|
1734
|
-
textNode.style
|
|
1735
|
-
);
|
|
1736
|
-
}
|
|
1714
|
+
results.push(child);
|
|
1737
1715
|
}
|
|
1738
1716
|
}
|
|
1739
1717
|
}
|
|
1740
|
-
if (
|
|
1741
|
-
|
|
1742
|
-
|
|
1718
|
+
if (textNodes.length > 0) {
|
|
1719
|
+
const mergedTextNode = this.mergeTextNodes(
|
|
1720
|
+
textNodes,
|
|
1743
1721
|
styleAttr
|
|
1744
1722
|
);
|
|
1745
|
-
|
|
1723
|
+
results.push(mergedTextNode);
|
|
1724
|
+
} else if (node.text.trim()) {
|
|
1725
|
+
results.push(this.createTextNode(node.text, styleAttr));
|
|
1746
1726
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
};
|
|
1727
|
+
return results;
|
|
1728
|
+
}
|
|
1729
|
+
mergeTextNodes(textNodes, spanStyle) {
|
|
1730
|
+
const result = { ...textNodes[0] };
|
|
1731
|
+
result.style = this.mergeStyles(result.style, spanStyle);
|
|
1732
|
+
for (let i = 1; i < textNodes.length; i++) {
|
|
1733
|
+
const node = textNodes[i];
|
|
1734
|
+
result.text += node.text;
|
|
1735
|
+
result.format |= node.format || 0;
|
|
1736
|
+
result.style = this.mergeStyles(result.style, node.style);
|
|
1758
1737
|
}
|
|
1759
|
-
return
|
|
1738
|
+
return result;
|
|
1739
|
+
}
|
|
1740
|
+
createTextNode(text, style) {
|
|
1741
|
+
return {
|
|
1742
|
+
detail: 0,
|
|
1743
|
+
format: 0,
|
|
1744
|
+
mode: "normal",
|
|
1745
|
+
style,
|
|
1746
|
+
text,
|
|
1747
|
+
type: "text",
|
|
1748
|
+
version: 1
|
|
1749
|
+
};
|
|
1760
1750
|
}
|
|
1761
1751
|
mergeStyles(existingStyle, newStyle) {
|
|
1762
|
-
if (!existingStyle) return
|
|
1763
|
-
if (!
|
|
1752
|
+
if (!existingStyle && !newStyle) return "";
|
|
1753
|
+
if (!existingStyle) return newStyle ?? "";
|
|
1754
|
+
if (!newStyle) return existingStyle ?? "";
|
|
1764
1755
|
return `${existingStyle};${newStyle}`.replace(/;;/g, ";").replace(/^;/, "").replace(/;$/, "");
|
|
1765
1756
|
}
|
|
1766
1757
|
};
|