@examind/block-sdk 0.1.13 → 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 CHANGED
@@ -261,14 +261,38 @@ var isSerializedImageNode = (node) => {
261
261
 
262
262
  // src/exportToHtml/ImageNodeHandler.ts
263
263
  var ImageNodeHandler = class extends NodeHandler {
264
- processNode(node) {
265
- if (!isSerializedImageNode(node)) return null;
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
- `src="${node.src}"`,
268
- node.altText ? `alt="${node.altText}"` : null,
269
- node.width ? `width="${node.width}"` : null,
270
- node.align !== "left" ? `align="${node.align}"` : null
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: false,
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: {
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
- processNode(node) {
238
- if (!isSerializedImageNode(node)) return null;
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
- `src="${node.src}"`,
241
- node.altText ? `alt="${node.altText}"` : null,
242
- node.width ? `width="${node.width}"` : null,
243
- node.align !== "left" ? `align="${node.align}"` : null
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: false,
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: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@examind/block-sdk",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "@comment version": [
5
5
  "Don't specify package version here. It will be injected by publish workflow."
6
6
  ],