@examind/block-sdk 0.2.4 → 0.2.6
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 +38 -31
- package/dist/index.mjs +38 -31
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -812,6 +812,9 @@ var TableCellNodeHandler = class extends NodeHandler {
|
|
|
812
812
|
} else if (!hasColspan && tableCellNode.width) {
|
|
813
813
|
styles.push(`width: ${tableCellNode.width}px;`);
|
|
814
814
|
}
|
|
815
|
+
if (tableCellNode.format) {
|
|
816
|
+
styles.push(`text-align: ${tableCellNode.format};`);
|
|
817
|
+
}
|
|
815
818
|
if (tableCellNode.backgroundColor) {
|
|
816
819
|
styles.push(
|
|
817
820
|
`background-color: ${tableCellNode.backgroundColor};`
|
|
@@ -1111,6 +1114,25 @@ var CustomQuestionNodeHandler2 = class extends NodeHandler2 {
|
|
|
1111
1114
|
// src/importFromHtml/DivNodeHandler.ts
|
|
1112
1115
|
var import_node_html_parser3 = require("node-html-parser");
|
|
1113
1116
|
|
|
1117
|
+
// src/utils/styleUtils.ts
|
|
1118
|
+
var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
|
|
1119
|
+
const regex = new RegExp(
|
|
1120
|
+
`${property}:[ ]*([^;]+)${unit ? unit : ""}`,
|
|
1121
|
+
"i"
|
|
1122
|
+
);
|
|
1123
|
+
const match = styleAttr.match(regex);
|
|
1124
|
+
if (!match || !match[1]) return null;
|
|
1125
|
+
const value = match[1].trim();
|
|
1126
|
+
return isNumeric ? parseFloat(value) : value;
|
|
1127
|
+
};
|
|
1128
|
+
var extractFormat = (cellAlign) => {
|
|
1129
|
+
if (!cellAlign) return "";
|
|
1130
|
+
if (cellAlign === "left") return "left";
|
|
1131
|
+
if (cellAlign === "right") return "right";
|
|
1132
|
+
if (cellAlign === "center") return "center";
|
|
1133
|
+
return "";
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1114
1136
|
// src/importFromHtml/createNestedNodesFromHtml.ts
|
|
1115
1137
|
var import_node_html_parser2 = require("node-html-parser");
|
|
1116
1138
|
var wrapInlinesInParagraph = (inlineNodes, format = "") => {
|
|
@@ -1124,24 +1146,13 @@ var appendInlinesInParagraphIfNotEmptyBR = (results, inlineNodes, format) => {
|
|
|
1124
1146
|
return;
|
|
1125
1147
|
results.push(wrapInlinesInParagraph(inlineNodes, format));
|
|
1126
1148
|
};
|
|
1127
|
-
var extractFormatFromStyle = (styleAttribute) => {
|
|
1128
|
-
if (!styleAttribute) return "";
|
|
1129
|
-
const textAlignMatch = styleAttribute.match(
|
|
1130
|
-
/text-align:\s*(left|right|center)/i
|
|
1131
|
-
);
|
|
1132
|
-
if (textAlignMatch) {
|
|
1133
|
-
const alignment = textAlignMatch[1].toLowerCase();
|
|
1134
|
-
if (alignment === "left") return "left";
|
|
1135
|
-
if (alignment === "right") return "right";
|
|
1136
|
-
if (alignment === "center") return "center";
|
|
1137
|
-
}
|
|
1138
|
-
return "";
|
|
1139
|
-
};
|
|
1140
1149
|
var createNestedNodesFromHtml = (node) => {
|
|
1141
|
-
const
|
|
1142
|
-
const
|
|
1150
|
+
const divParentStyleAttribute = node instanceof import_node_html_parser2.HTMLElement && node.tagName === "DIV" ? node.getAttribute("style") : null;
|
|
1151
|
+
const divParentFormat = extractFormat(
|
|
1152
|
+
extractStyleValue(divParentStyleAttribute ?? "", "text-align")
|
|
1153
|
+
);
|
|
1143
1154
|
if (node.childNodes.length === 1 && node.childNodes[0] instanceof import_node_html_parser2.HTMLElement && node.childNodes[0].tagName === "BR") {
|
|
1144
|
-
return [createEmptyParagraphNode(
|
|
1155
|
+
return [createEmptyParagraphNode(divParentFormat)];
|
|
1145
1156
|
}
|
|
1146
1157
|
const results = [];
|
|
1147
1158
|
let inlineNodes = [];
|
|
@@ -1155,7 +1166,7 @@ var createNestedNodesFromHtml = (node) => {
|
|
|
1155
1166
|
appendInlinesInParagraphIfNotEmptyBR(
|
|
1156
1167
|
results,
|
|
1157
1168
|
inlineNodes,
|
|
1158
|
-
|
|
1169
|
+
divParentFormat
|
|
1159
1170
|
);
|
|
1160
1171
|
inlineNodes = [];
|
|
1161
1172
|
results.push(processedChild);
|
|
@@ -1164,8 +1175,13 @@ var createNestedNodesFromHtml = (node) => {
|
|
|
1164
1175
|
}
|
|
1165
1176
|
}
|
|
1166
1177
|
}
|
|
1167
|
-
appendInlinesInParagraphIfNotEmptyBR(
|
|
1168
|
-
|
|
1178
|
+
appendInlinesInParagraphIfNotEmptyBR(
|
|
1179
|
+
results,
|
|
1180
|
+
inlineNodes,
|
|
1181
|
+
divParentFormat
|
|
1182
|
+
);
|
|
1183
|
+
if (results.length === 0)
|
|
1184
|
+
return [createEmptyParagraphNode(divParentFormat)];
|
|
1169
1185
|
else return results;
|
|
1170
1186
|
};
|
|
1171
1187
|
|
|
@@ -2223,18 +2239,6 @@ var SpanNodeHandler = class extends NodeHandler2 {
|
|
|
2223
2239
|
// src/importFromHtml/TableCellNodeHandler.ts
|
|
2224
2240
|
var import_node_html_parser26 = require("node-html-parser");
|
|
2225
2241
|
|
|
2226
|
-
// src/utils/styleUtils.ts
|
|
2227
|
-
var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
|
|
2228
|
-
const regex = new RegExp(
|
|
2229
|
-
`${property}:[ ]*([^;]+)${unit ? unit : ""}`,
|
|
2230
|
-
"i"
|
|
2231
|
-
);
|
|
2232
|
-
const match = styleAttr.match(regex);
|
|
2233
|
-
if (!match || !match[1]) return null;
|
|
2234
|
-
const value = match[1].trim();
|
|
2235
|
-
return isNumeric ? parseFloat(value) : value;
|
|
2236
|
-
};
|
|
2237
|
-
|
|
2238
2242
|
// src/importFromHtml/createTableNodes.ts
|
|
2239
2243
|
function createEmptyTableNode() {
|
|
2240
2244
|
return {
|
|
@@ -2306,6 +2310,9 @@ var TableCellNodeHandler2 = class extends NodeHandler2 {
|
|
|
2306
2310
|
if (verticalAlign !== null) {
|
|
2307
2311
|
cellNode.verticalAlign = verticalAlign;
|
|
2308
2312
|
}
|
|
2313
|
+
cellNode.format = extractFormat(
|
|
2314
|
+
extractStyleValue(styleAttr, "text-align")
|
|
2315
|
+
);
|
|
2309
2316
|
cellNode.children = createNestedNodesFromHtml(node);
|
|
2310
2317
|
return cellNode;
|
|
2311
2318
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -785,6 +785,9 @@ var TableCellNodeHandler = class extends NodeHandler {
|
|
|
785
785
|
} else if (!hasColspan && tableCellNode.width) {
|
|
786
786
|
styles.push(`width: ${tableCellNode.width}px;`);
|
|
787
787
|
}
|
|
788
|
+
if (tableCellNode.format) {
|
|
789
|
+
styles.push(`text-align: ${tableCellNode.format};`);
|
|
790
|
+
}
|
|
788
791
|
if (tableCellNode.backgroundColor) {
|
|
789
792
|
styles.push(
|
|
790
793
|
`background-color: ${tableCellNode.backgroundColor};`
|
|
@@ -1084,6 +1087,25 @@ var CustomQuestionNodeHandler2 = class extends NodeHandler2 {
|
|
|
1084
1087
|
// src/importFromHtml/DivNodeHandler.ts
|
|
1085
1088
|
import { HTMLElement as HTMLElement3 } from "node-html-parser";
|
|
1086
1089
|
|
|
1090
|
+
// src/utils/styleUtils.ts
|
|
1091
|
+
var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
|
|
1092
|
+
const regex = new RegExp(
|
|
1093
|
+
`${property}:[ ]*([^;]+)${unit ? unit : ""}`,
|
|
1094
|
+
"i"
|
|
1095
|
+
);
|
|
1096
|
+
const match = styleAttr.match(regex);
|
|
1097
|
+
if (!match || !match[1]) return null;
|
|
1098
|
+
const value = match[1].trim();
|
|
1099
|
+
return isNumeric ? parseFloat(value) : value;
|
|
1100
|
+
};
|
|
1101
|
+
var extractFormat = (cellAlign) => {
|
|
1102
|
+
if (!cellAlign) return "";
|
|
1103
|
+
if (cellAlign === "left") return "left";
|
|
1104
|
+
if (cellAlign === "right") return "right";
|
|
1105
|
+
if (cellAlign === "center") return "center";
|
|
1106
|
+
return "";
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1087
1109
|
// src/importFromHtml/createNestedNodesFromHtml.ts
|
|
1088
1110
|
import { HTMLElement as HTMLElement2 } from "node-html-parser";
|
|
1089
1111
|
var wrapInlinesInParagraph = (inlineNodes, format = "") => {
|
|
@@ -1097,24 +1119,13 @@ var appendInlinesInParagraphIfNotEmptyBR = (results, inlineNodes, format) => {
|
|
|
1097
1119
|
return;
|
|
1098
1120
|
results.push(wrapInlinesInParagraph(inlineNodes, format));
|
|
1099
1121
|
};
|
|
1100
|
-
var extractFormatFromStyle = (styleAttribute) => {
|
|
1101
|
-
if (!styleAttribute) return "";
|
|
1102
|
-
const textAlignMatch = styleAttribute.match(
|
|
1103
|
-
/text-align:\s*(left|right|center)/i
|
|
1104
|
-
);
|
|
1105
|
-
if (textAlignMatch) {
|
|
1106
|
-
const alignment = textAlignMatch[1].toLowerCase();
|
|
1107
|
-
if (alignment === "left") return "left";
|
|
1108
|
-
if (alignment === "right") return "right";
|
|
1109
|
-
if (alignment === "center") return "center";
|
|
1110
|
-
}
|
|
1111
|
-
return "";
|
|
1112
|
-
};
|
|
1113
1122
|
var createNestedNodesFromHtml = (node) => {
|
|
1114
|
-
const
|
|
1115
|
-
const
|
|
1123
|
+
const divParentStyleAttribute = node instanceof HTMLElement2 && node.tagName === "DIV" ? node.getAttribute("style") : null;
|
|
1124
|
+
const divParentFormat = extractFormat(
|
|
1125
|
+
extractStyleValue(divParentStyleAttribute ?? "", "text-align")
|
|
1126
|
+
);
|
|
1116
1127
|
if (node.childNodes.length === 1 && node.childNodes[0] instanceof HTMLElement2 && node.childNodes[0].tagName === "BR") {
|
|
1117
|
-
return [createEmptyParagraphNode(
|
|
1128
|
+
return [createEmptyParagraphNode(divParentFormat)];
|
|
1118
1129
|
}
|
|
1119
1130
|
const results = [];
|
|
1120
1131
|
let inlineNodes = [];
|
|
@@ -1128,7 +1139,7 @@ var createNestedNodesFromHtml = (node) => {
|
|
|
1128
1139
|
appendInlinesInParagraphIfNotEmptyBR(
|
|
1129
1140
|
results,
|
|
1130
1141
|
inlineNodes,
|
|
1131
|
-
|
|
1142
|
+
divParentFormat
|
|
1132
1143
|
);
|
|
1133
1144
|
inlineNodes = [];
|
|
1134
1145
|
results.push(processedChild);
|
|
@@ -1137,8 +1148,13 @@ var createNestedNodesFromHtml = (node) => {
|
|
|
1137
1148
|
}
|
|
1138
1149
|
}
|
|
1139
1150
|
}
|
|
1140
|
-
appendInlinesInParagraphIfNotEmptyBR(
|
|
1141
|
-
|
|
1151
|
+
appendInlinesInParagraphIfNotEmptyBR(
|
|
1152
|
+
results,
|
|
1153
|
+
inlineNodes,
|
|
1154
|
+
divParentFormat
|
|
1155
|
+
);
|
|
1156
|
+
if (results.length === 0)
|
|
1157
|
+
return [createEmptyParagraphNode(divParentFormat)];
|
|
1142
1158
|
else return results;
|
|
1143
1159
|
};
|
|
1144
1160
|
|
|
@@ -2196,18 +2212,6 @@ var SpanNodeHandler = class extends NodeHandler2 {
|
|
|
2196
2212
|
// src/importFromHtml/TableCellNodeHandler.ts
|
|
2197
2213
|
import { HTMLElement as HTMLElement26 } from "node-html-parser";
|
|
2198
2214
|
|
|
2199
|
-
// src/utils/styleUtils.ts
|
|
2200
|
-
var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
|
|
2201
|
-
const regex = new RegExp(
|
|
2202
|
-
`${property}:[ ]*([^;]+)${unit ? unit : ""}`,
|
|
2203
|
-
"i"
|
|
2204
|
-
);
|
|
2205
|
-
const match = styleAttr.match(regex);
|
|
2206
|
-
if (!match || !match[1]) return null;
|
|
2207
|
-
const value = match[1].trim();
|
|
2208
|
-
return isNumeric ? parseFloat(value) : value;
|
|
2209
|
-
};
|
|
2210
|
-
|
|
2211
2215
|
// src/importFromHtml/createTableNodes.ts
|
|
2212
2216
|
function createEmptyTableNode() {
|
|
2213
2217
|
return {
|
|
@@ -2279,6 +2283,9 @@ var TableCellNodeHandler2 = class extends NodeHandler2 {
|
|
|
2279
2283
|
if (verticalAlign !== null) {
|
|
2280
2284
|
cellNode.verticalAlign = verticalAlign;
|
|
2281
2285
|
}
|
|
2286
|
+
cellNode.format = extractFormat(
|
|
2287
|
+
extractStyleValue(styleAttr, "text-align")
|
|
2288
|
+
);
|
|
2282
2289
|
cellNode.children = createNestedNodesFromHtml(node);
|
|
2283
2290
|
return cellNode;
|
|
2284
2291
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@examind/block-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"@comment version": [
|
|
5
5
|
"Don't specify package version here. It will be injected by publish workflow."
|
|
6
6
|
],
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"nanoid": ">=3.0.0",
|
|
23
23
|
"node-html-parser": ">=6.0.0",
|
|
24
|
-
"@examind/block-types": "^0.2.
|
|
24
|
+
"@examind/block-types": "^0.2.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@eslint/js": "^9.17.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"tsup": "^8.3.5",
|
|
37
37
|
"typescript": "^5.7.2",
|
|
38
38
|
"typescript-eslint": "^8.18.2",
|
|
39
|
-
"@examind/block-types": "0.2.
|
|
39
|
+
"@examind/block-types": "0.2.6"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"lodash-es": "4.17.21"
|