@scrider/formatter 1.8.6 → 1.8.7
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.cjs +22 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -757,6 +757,7 @@ function toCodeWidgetEmbedUrl(url) {
|
|
|
757
757
|
var EXT_TABLE_HOST_ATTR = "data-scrider-ext-table";
|
|
758
758
|
var EXT_TABLE_HOST_CLASS = "scrider-ext-table-host";
|
|
759
759
|
var VALID_TABLE_BLOCK_FLOATS = ["left", "center", "right"];
|
|
760
|
+
var VALID_TABLE_BLOCK_ALIGNS = ["left", "center", "right", "justify"];
|
|
760
761
|
var VALID_CELL_HORIZONTAL_ALIGNS = [
|
|
761
762
|
"left",
|
|
762
763
|
"center",
|
|
@@ -960,6 +961,12 @@ function parseTableBlockFloat(value) {
|
|
|
960
961
|
if (value === "left" || value === "center" || value === "right") return value;
|
|
961
962
|
return void 0;
|
|
962
963
|
}
|
|
964
|
+
function parseTableBlockAlign(value) {
|
|
965
|
+
if (value === "left" || value === "center" || value === "right" || value === "justify") {
|
|
966
|
+
return value;
|
|
967
|
+
}
|
|
968
|
+
return void 0;
|
|
969
|
+
}
|
|
963
970
|
function extractHostBlockWidthPx(host) {
|
|
964
971
|
const style = host.getAttribute("style") || "";
|
|
965
972
|
const widthMatch = style.match(/(?:^|;\s*)width:\s*([\d.]+)px/i);
|
|
@@ -970,25 +977,32 @@ function extractHostBlockWidthPx(host) {
|
|
|
970
977
|
}
|
|
971
978
|
function enrichTableBlockFromHost(data, host) {
|
|
972
979
|
const float = parseTableBlockFloat(host.getAttribute("data-float"));
|
|
980
|
+
const blockAlign = parseTableBlockAlign(host.getAttribute("data-block-align"));
|
|
973
981
|
const width = extractHostBlockWidthPx(host);
|
|
974
|
-
if (float == null && width == null) return data;
|
|
982
|
+
if (float == null && blockAlign == null && width == null) return data;
|
|
975
983
|
const next = { ...data };
|
|
976
984
|
if (float != null) next.float = float;
|
|
985
|
+
if (blockAlign != null && float == null) next.blockAlign = blockAlign;
|
|
977
986
|
if (width != null) next.width = width;
|
|
978
987
|
return next;
|
|
979
988
|
}
|
|
980
989
|
function tableNeedsHostWrapper(data) {
|
|
981
|
-
return data.float != null && VALID_TABLE_BLOCK_FLOATS.includes(data.float) || data.width != null && data.width > 0;
|
|
990
|
+
return data.float != null && VALID_TABLE_BLOCK_FLOATS.includes(data.float) || data.width != null && data.width > 0 || data.float == null && data.blockAlign != null && VALID_TABLE_BLOCK_ALIGNS.includes(data.blockAlign);
|
|
982
991
|
}
|
|
983
992
|
function renderTableHostWrapperOpen(data, pretty) {
|
|
984
993
|
const nl = pretty ? "\n" : "";
|
|
985
994
|
const ind = pretty ? " " : "";
|
|
986
995
|
const attrs = [`class="${EXT_TABLE_HOST_CLASS}"`, EXT_TABLE_HOST_ATTR];
|
|
987
996
|
if (data.float) attrs.push(`data-float="${escapeHtml(data.float)}"`);
|
|
997
|
+
if (data.blockAlign && !data.float) {
|
|
998
|
+
attrs.push(`data-block-align="${escapeHtml(data.blockAlign)}"`);
|
|
999
|
+
}
|
|
988
1000
|
const styleParts = [];
|
|
989
1001
|
if (data.width != null && data.width > 0) {
|
|
990
1002
|
styleParts.push(`width: ${Math.round(data.width)}px`);
|
|
991
1003
|
styleParts.push("max-width: 100%");
|
|
1004
|
+
} else if (data.blockAlign === "justify" && !data.float) {
|
|
1005
|
+
styleParts.push("width: 100%");
|
|
992
1006
|
}
|
|
993
1007
|
if (styleParts.length > 0) attrs.push(`style="${styleParts.join("; ")}"`);
|
|
994
1008
|
return `<div ${attrs.join(" ")}>${nl}${ind}`;
|
|
@@ -1009,6 +1023,9 @@ function isGfmCompatible(data) {
|
|
|
1009
1023
|
if (data.float != null) {
|
|
1010
1024
|
return false;
|
|
1011
1025
|
}
|
|
1026
|
+
if (data.blockAlign != null) {
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1012
1029
|
for (const cell of Object.values(data.cells)) {
|
|
1013
1030
|
if (cell !== null && cell.align !== void 0) return false;
|
|
1014
1031
|
}
|
|
@@ -1393,6 +1410,9 @@ var tableBlockHandler = {
|
|
|
1393
1410
|
if (data.float !== void 0 && !VALID_TABLE_BLOCK_FLOATS.includes(data.float)) {
|
|
1394
1411
|
return false;
|
|
1395
1412
|
}
|
|
1413
|
+
if (data.blockAlign !== void 0 && !VALID_TABLE_BLOCK_ALIGNS.includes(data.blockAlign)) {
|
|
1414
|
+
return false;
|
|
1415
|
+
}
|
|
1396
1416
|
if (data.colAligns !== void 0) {
|
|
1397
1417
|
if (!Array.isArray(data.colAligns) || data.colAligns.length !== cols) {
|
|
1398
1418
|
return false;
|