@examind/block-sdk 0.1.12 → 0.1.14
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 +78 -32
- package/dist/index.mjs +78 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -261,14 +261,38 @@ var isSerializedImageNode = (node) => {
|
|
|
261
261
|
|
|
262
262
|
// src/exportToHtml/ImageNodeHandler.ts
|
|
263
263
|
var ImageNodeHandler = class extends NodeHandler {
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
srcAttribute(node) {
|
|
265
|
+
return `src="${node.src}"`;
|
|
266
|
+
}
|
|
267
|
+
altAttribute(node) {
|
|
268
|
+
return node.altText ? `alt="${node.altText}"` : null;
|
|
269
|
+
}
|
|
270
|
+
styleAttribute(node) {
|
|
271
|
+
const styleProps = [];
|
|
272
|
+
if (node.width) {
|
|
273
|
+
styleProps.push(`width: ${node.width};`);
|
|
274
|
+
styleProps.push(`max-width: 100%;`);
|
|
275
|
+
}
|
|
276
|
+
if (node.showBorder) {
|
|
277
|
+
styleProps.push(`border: 1px solid #ccc;`);
|
|
278
|
+
}
|
|
279
|
+
return styleProps.length ? `style="${styleProps.join(" ")}"` : null;
|
|
280
|
+
}
|
|
281
|
+
alignAttribute(node) {
|
|
282
|
+
return node.align !== "left" ? `align="${node.align}"` : null;
|
|
283
|
+
}
|
|
284
|
+
attributes(node) {
|
|
266
285
|
const attributes = [
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
286
|
+
this.srcAttribute(node),
|
|
287
|
+
this.altAttribute(node),
|
|
288
|
+
this.styleAttribute(node),
|
|
289
|
+
this.alignAttribute(node)
|
|
271
290
|
].filter(Boolean).join(" ");
|
|
291
|
+
return attributes;
|
|
292
|
+
}
|
|
293
|
+
processNode(node) {
|
|
294
|
+
if (!isSerializedImageNode(node)) return null;
|
|
295
|
+
const attributes = this.attributes(node);
|
|
272
296
|
return `<img ${attributes} />`;
|
|
273
297
|
}
|
|
274
298
|
};
|
|
@@ -1312,20 +1336,32 @@ var HorizontalRuleNodeHandler2 = class extends NodeHandler2 {
|
|
|
1312
1336
|
var import_node_html_parser9 = require("node-html-parser");
|
|
1313
1337
|
var TAG_IMG = "img";
|
|
1314
1338
|
var ImageNodeHandler2 = class extends NodeHandler2 {
|
|
1339
|
+
extractWidth(element) {
|
|
1340
|
+
const style = element.getAttribute("style");
|
|
1341
|
+
if (style) {
|
|
1342
|
+
const widthMatch = style.match(/width:\s*([^;]+);?/i);
|
|
1343
|
+
if (widthMatch && widthMatch[1]) {
|
|
1344
|
+
return widthMatch[1].trim();
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
const width = element.getAttribute("width");
|
|
1348
|
+
return width ? `${width}px` : "";
|
|
1349
|
+
}
|
|
1350
|
+
hasBorder(element) {
|
|
1351
|
+
const style = element.getAttribute("style");
|
|
1352
|
+
if (!style) return false;
|
|
1353
|
+
return /border\s*:/i.test(style);
|
|
1354
|
+
}
|
|
1315
1355
|
processNode(node) {
|
|
1316
1356
|
if (!(node instanceof import_node_html_parser9.HTMLElement) || node.tagName !== TAG_IMG.toUpperCase()) {
|
|
1317
1357
|
return null;
|
|
1318
1358
|
}
|
|
1319
|
-
const src = node.getAttribute("src") || "";
|
|
1320
|
-
const altText = node.getAttribute("alt") || "";
|
|
1321
|
-
const width = node.getAttribute("width") || "";
|
|
1322
|
-
const align = node.getAttribute("align") || "left";
|
|
1323
1359
|
const imageNode = {
|
|
1324
|
-
src,
|
|
1325
|
-
altText,
|
|
1326
|
-
width,
|
|
1327
|
-
align,
|
|
1328
|
-
showBorder:
|
|
1360
|
+
src: node.getAttribute("src") || "",
|
|
1361
|
+
altText: node.getAttribute("alt") || "",
|
|
1362
|
+
width: this.extractWidth(node),
|
|
1363
|
+
align: node.getAttribute("align") || "left",
|
|
1364
|
+
showBorder: this.hasBorder(node),
|
|
1329
1365
|
showCaption: false,
|
|
1330
1366
|
caption: {
|
|
1331
1367
|
editorState: {
|
|
@@ -1730,29 +1766,39 @@ var SpanNodeHandler = class extends NodeHandler2 {
|
|
|
1730
1766
|
if (node.childNodes.length === 1 && node.childNodes[0] instanceof TextNode) {
|
|
1731
1767
|
return this.createTextNode(node.text, styleAttr);
|
|
1732
1768
|
}
|
|
1733
|
-
|
|
1769
|
+
const results = [];
|
|
1770
|
+
const textNodes = [];
|
|
1734
1771
|
for (const childNode of node.childNodes) {
|
|
1735
1772
|
for (const child of traverse2(childNode)) {
|
|
1736
|
-
if (child.type
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
childResult = {
|
|
1740
|
-
...textNode,
|
|
1741
|
-
style: this.mergeStyles(textNode.style, styleAttr)
|
|
1742
|
-
};
|
|
1773
|
+
if (child.type === "text") {
|
|
1774
|
+
const textNode = child;
|
|
1775
|
+
textNodes.push(textNode);
|
|
1743
1776
|
} else {
|
|
1744
|
-
|
|
1745
|
-
childResult.format |= textNode.format || 0;
|
|
1746
|
-
childResult.style = this.mergeStyles(
|
|
1747
|
-
childResult.style,
|
|
1748
|
-
textNode.style
|
|
1749
|
-
);
|
|
1777
|
+
results.push(child);
|
|
1750
1778
|
}
|
|
1751
1779
|
}
|
|
1752
1780
|
}
|
|
1753
|
-
if (
|
|
1754
|
-
|
|
1755
|
-
|
|
1781
|
+
if (textNodes.length > 0) {
|
|
1782
|
+
const mergedTextNode = this.mergeTextNodes(
|
|
1783
|
+
textNodes,
|
|
1784
|
+
styleAttr
|
|
1785
|
+
);
|
|
1786
|
+
results.push(mergedTextNode);
|
|
1787
|
+
} else if (node.text.trim()) {
|
|
1788
|
+
results.push(this.createTextNode(node.text, styleAttr));
|
|
1789
|
+
}
|
|
1790
|
+
return results;
|
|
1791
|
+
}
|
|
1792
|
+
mergeTextNodes(textNodes, spanStyle) {
|
|
1793
|
+
const result = { ...textNodes[0] };
|
|
1794
|
+
result.style = this.mergeStyles(result.style, spanStyle);
|
|
1795
|
+
for (let i = 1; i < textNodes.length; i++) {
|
|
1796
|
+
const node = textNodes[i];
|
|
1797
|
+
result.text += node.text;
|
|
1798
|
+
result.format |= node.format || 0;
|
|
1799
|
+
result.style = this.mergeStyles(result.style, node.style);
|
|
1800
|
+
}
|
|
1801
|
+
return result;
|
|
1756
1802
|
}
|
|
1757
1803
|
createTextNode(text, style) {
|
|
1758
1804
|
return {
|
package/dist/index.mjs
CHANGED
|
@@ -234,14 +234,38 @@ var isSerializedImageNode = (node) => {
|
|
|
234
234
|
|
|
235
235
|
// src/exportToHtml/ImageNodeHandler.ts
|
|
236
236
|
var ImageNodeHandler = class extends NodeHandler {
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
srcAttribute(node) {
|
|
238
|
+
return `src="${node.src}"`;
|
|
239
|
+
}
|
|
240
|
+
altAttribute(node) {
|
|
241
|
+
return node.altText ? `alt="${node.altText}"` : null;
|
|
242
|
+
}
|
|
243
|
+
styleAttribute(node) {
|
|
244
|
+
const styleProps = [];
|
|
245
|
+
if (node.width) {
|
|
246
|
+
styleProps.push(`width: ${node.width};`);
|
|
247
|
+
styleProps.push(`max-width: 100%;`);
|
|
248
|
+
}
|
|
249
|
+
if (node.showBorder) {
|
|
250
|
+
styleProps.push(`border: 1px solid #ccc;`);
|
|
251
|
+
}
|
|
252
|
+
return styleProps.length ? `style="${styleProps.join(" ")}"` : null;
|
|
253
|
+
}
|
|
254
|
+
alignAttribute(node) {
|
|
255
|
+
return node.align !== "left" ? `align="${node.align}"` : null;
|
|
256
|
+
}
|
|
257
|
+
attributes(node) {
|
|
239
258
|
const attributes = [
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
259
|
+
this.srcAttribute(node),
|
|
260
|
+
this.altAttribute(node),
|
|
261
|
+
this.styleAttribute(node),
|
|
262
|
+
this.alignAttribute(node)
|
|
244
263
|
].filter(Boolean).join(" ");
|
|
264
|
+
return attributes;
|
|
265
|
+
}
|
|
266
|
+
processNode(node) {
|
|
267
|
+
if (!isSerializedImageNode(node)) return null;
|
|
268
|
+
const attributes = this.attributes(node);
|
|
245
269
|
return `<img ${attributes} />`;
|
|
246
270
|
}
|
|
247
271
|
};
|
|
@@ -1285,20 +1309,32 @@ var HorizontalRuleNodeHandler2 = class extends NodeHandler2 {
|
|
|
1285
1309
|
import { HTMLElement as HTMLElement9 } from "node-html-parser";
|
|
1286
1310
|
var TAG_IMG = "img";
|
|
1287
1311
|
var ImageNodeHandler2 = class extends NodeHandler2 {
|
|
1312
|
+
extractWidth(element) {
|
|
1313
|
+
const style = element.getAttribute("style");
|
|
1314
|
+
if (style) {
|
|
1315
|
+
const widthMatch = style.match(/width:\s*([^;]+);?/i);
|
|
1316
|
+
if (widthMatch && widthMatch[1]) {
|
|
1317
|
+
return widthMatch[1].trim();
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
const width = element.getAttribute("width");
|
|
1321
|
+
return width ? `${width}px` : "";
|
|
1322
|
+
}
|
|
1323
|
+
hasBorder(element) {
|
|
1324
|
+
const style = element.getAttribute("style");
|
|
1325
|
+
if (!style) return false;
|
|
1326
|
+
return /border\s*:/i.test(style);
|
|
1327
|
+
}
|
|
1288
1328
|
processNode(node) {
|
|
1289
1329
|
if (!(node instanceof HTMLElement9) || node.tagName !== TAG_IMG.toUpperCase()) {
|
|
1290
1330
|
return null;
|
|
1291
1331
|
}
|
|
1292
|
-
const src = node.getAttribute("src") || "";
|
|
1293
|
-
const altText = node.getAttribute("alt") || "";
|
|
1294
|
-
const width = node.getAttribute("width") || "";
|
|
1295
|
-
const align = node.getAttribute("align") || "left";
|
|
1296
1332
|
const imageNode = {
|
|
1297
|
-
src,
|
|
1298
|
-
altText,
|
|
1299
|
-
width,
|
|
1300
|
-
align,
|
|
1301
|
-
showBorder:
|
|
1333
|
+
src: node.getAttribute("src") || "",
|
|
1334
|
+
altText: node.getAttribute("alt") || "",
|
|
1335
|
+
width: this.extractWidth(node),
|
|
1336
|
+
align: node.getAttribute("align") || "left",
|
|
1337
|
+
showBorder: this.hasBorder(node),
|
|
1302
1338
|
showCaption: false,
|
|
1303
1339
|
caption: {
|
|
1304
1340
|
editorState: {
|
|
@@ -1703,29 +1739,39 @@ var SpanNodeHandler = class extends NodeHandler2 {
|
|
|
1703
1739
|
if (node.childNodes.length === 1 && node.childNodes[0] instanceof TextNode) {
|
|
1704
1740
|
return this.createTextNode(node.text, styleAttr);
|
|
1705
1741
|
}
|
|
1706
|
-
|
|
1742
|
+
const results = [];
|
|
1743
|
+
const textNodes = [];
|
|
1707
1744
|
for (const childNode of node.childNodes) {
|
|
1708
1745
|
for (const child of traverse2(childNode)) {
|
|
1709
|
-
if (child.type
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
childResult = {
|
|
1713
|
-
...textNode,
|
|
1714
|
-
style: this.mergeStyles(textNode.style, styleAttr)
|
|
1715
|
-
};
|
|
1746
|
+
if (child.type === "text") {
|
|
1747
|
+
const textNode = child;
|
|
1748
|
+
textNodes.push(textNode);
|
|
1716
1749
|
} else {
|
|
1717
|
-
|
|
1718
|
-
childResult.format |= textNode.format || 0;
|
|
1719
|
-
childResult.style = this.mergeStyles(
|
|
1720
|
-
childResult.style,
|
|
1721
|
-
textNode.style
|
|
1722
|
-
);
|
|
1750
|
+
results.push(child);
|
|
1723
1751
|
}
|
|
1724
1752
|
}
|
|
1725
1753
|
}
|
|
1726
|
-
if (
|
|
1727
|
-
|
|
1728
|
-
|
|
1754
|
+
if (textNodes.length > 0) {
|
|
1755
|
+
const mergedTextNode = this.mergeTextNodes(
|
|
1756
|
+
textNodes,
|
|
1757
|
+
styleAttr
|
|
1758
|
+
);
|
|
1759
|
+
results.push(mergedTextNode);
|
|
1760
|
+
} else if (node.text.trim()) {
|
|
1761
|
+
results.push(this.createTextNode(node.text, styleAttr));
|
|
1762
|
+
}
|
|
1763
|
+
return results;
|
|
1764
|
+
}
|
|
1765
|
+
mergeTextNodes(textNodes, spanStyle) {
|
|
1766
|
+
const result = { ...textNodes[0] };
|
|
1767
|
+
result.style = this.mergeStyles(result.style, spanStyle);
|
|
1768
|
+
for (let i = 1; i < textNodes.length; i++) {
|
|
1769
|
+
const node = textNodes[i];
|
|
1770
|
+
result.text += node.text;
|
|
1771
|
+
result.format |= node.format || 0;
|
|
1772
|
+
result.style = this.mergeStyles(result.style, node.style);
|
|
1773
|
+
}
|
|
1774
|
+
return result;
|
|
1729
1775
|
}
|
|
1730
1776
|
createTextNode(text, style) {
|
|
1731
1777
|
return {
|