@scrider/formatter 1.8.6 → 1.9.1
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 +60 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -1
- package/dist/index.d.ts +84 -1
- package/dist/index.js +59 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -73,6 +73,7 @@ __export(index_exports, {
|
|
|
73
73
|
deltaToHtml: () => deltaToHtml,
|
|
74
74
|
deltaToMarkdown: () => deltaToMarkdown,
|
|
75
75
|
dividerFormat: () => dividerFormat,
|
|
76
|
+
documentMetadataToPresentation: () => documentMetadataToPresentation,
|
|
76
77
|
documentPresentationStyleParts: () => documentPresentationStyleParts,
|
|
77
78
|
escapeHtml: () => escapeHtml,
|
|
78
79
|
extractBoxOpAttributes: () => extractBoxOpAttributes,
|
|
@@ -757,6 +758,7 @@ function toCodeWidgetEmbedUrl(url) {
|
|
|
757
758
|
var EXT_TABLE_HOST_ATTR = "data-scrider-ext-table";
|
|
758
759
|
var EXT_TABLE_HOST_CLASS = "scrider-ext-table-host";
|
|
759
760
|
var VALID_TABLE_BLOCK_FLOATS = ["left", "center", "right"];
|
|
761
|
+
var VALID_TABLE_BLOCK_ALIGNS = ["left", "center", "right", "justify"];
|
|
760
762
|
var VALID_CELL_HORIZONTAL_ALIGNS = [
|
|
761
763
|
"left",
|
|
762
764
|
"center",
|
|
@@ -960,6 +962,12 @@ function parseTableBlockFloat(value) {
|
|
|
960
962
|
if (value === "left" || value === "center" || value === "right") return value;
|
|
961
963
|
return void 0;
|
|
962
964
|
}
|
|
965
|
+
function parseTableBlockAlign(value) {
|
|
966
|
+
if (value === "left" || value === "center" || value === "right" || value === "justify") {
|
|
967
|
+
return value;
|
|
968
|
+
}
|
|
969
|
+
return void 0;
|
|
970
|
+
}
|
|
963
971
|
function extractHostBlockWidthPx(host) {
|
|
964
972
|
const style = host.getAttribute("style") || "";
|
|
965
973
|
const widthMatch = style.match(/(?:^|;\s*)width:\s*([\d.]+)px/i);
|
|
@@ -970,25 +978,34 @@ function extractHostBlockWidthPx(host) {
|
|
|
970
978
|
}
|
|
971
979
|
function enrichTableBlockFromHost(data, host) {
|
|
972
980
|
const float = parseTableBlockFloat(host.getAttribute("data-float"));
|
|
981
|
+
const blockAlign = parseTableBlockAlign(host.getAttribute("data-block-align"));
|
|
973
982
|
const width = extractHostBlockWidthPx(host);
|
|
974
|
-
if (float == null && width == null) return data;
|
|
983
|
+
if (float == null && blockAlign == null && width == null) return data;
|
|
975
984
|
const next = { ...data };
|
|
976
985
|
if (float != null) next.float = float;
|
|
986
|
+
if (blockAlign != null && float == null) next.blockAlign = blockAlign;
|
|
977
987
|
if (width != null) next.width = width;
|
|
978
988
|
return next;
|
|
979
989
|
}
|
|
980
990
|
function tableNeedsHostWrapper(data) {
|
|
981
|
-
return data.float != null && VALID_TABLE_BLOCK_FLOATS.includes(data.float) || data.width != null && data.width > 0;
|
|
991
|
+
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
992
|
}
|
|
983
993
|
function renderTableHostWrapperOpen(data, pretty) {
|
|
984
994
|
const nl = pretty ? "\n" : "";
|
|
985
995
|
const ind = pretty ? " " : "";
|
|
986
996
|
const attrs = [`class="${EXT_TABLE_HOST_CLASS}"`, EXT_TABLE_HOST_ATTR];
|
|
987
997
|
if (data.float) attrs.push(`data-float="${escapeHtml(data.float)}"`);
|
|
998
|
+
if (data.blockAlign && !data.float) {
|
|
999
|
+
attrs.push(`data-block-align="${escapeHtml(data.blockAlign)}"`);
|
|
1000
|
+
}
|
|
988
1001
|
const styleParts = [];
|
|
989
|
-
if (data.
|
|
1002
|
+
if (data.blockAlign === "justify" && !data.float) {
|
|
1003
|
+
styleParts.push("width: 100%");
|
|
1004
|
+
} else if (data.width != null && data.width > 0) {
|
|
990
1005
|
styleParts.push(`width: ${Math.round(data.width)}px`);
|
|
991
1006
|
styleParts.push("max-width: 100%");
|
|
1007
|
+
} else if (data.blockAlign && !data.float) {
|
|
1008
|
+
styleParts.push("width: 100%");
|
|
992
1009
|
}
|
|
993
1010
|
if (styleParts.length > 0) attrs.push(`style="${styleParts.join("; ")}"`);
|
|
994
1011
|
return `<div ${attrs.join(" ")}>${nl}${ind}`;
|
|
@@ -1009,6 +1026,9 @@ function isGfmCompatible(data) {
|
|
|
1009
1026
|
if (data.float != null) {
|
|
1010
1027
|
return false;
|
|
1011
1028
|
}
|
|
1029
|
+
if (data.blockAlign != null) {
|
|
1030
|
+
return false;
|
|
1031
|
+
}
|
|
1012
1032
|
for (const cell of Object.values(data.cells)) {
|
|
1013
1033
|
if (cell !== null && cell.align !== void 0) return false;
|
|
1014
1034
|
}
|
|
@@ -1393,6 +1413,9 @@ var tableBlockHandler = {
|
|
|
1393
1413
|
if (data.float !== void 0 && !VALID_TABLE_BLOCK_FLOATS.includes(data.float)) {
|
|
1394
1414
|
return false;
|
|
1395
1415
|
}
|
|
1416
|
+
if (data.blockAlign !== void 0 && !VALID_TABLE_BLOCK_ALIGNS.includes(data.blockAlign)) {
|
|
1417
|
+
return false;
|
|
1418
|
+
}
|
|
1396
1419
|
if (data.colAligns !== void 0) {
|
|
1397
1420
|
if (!Array.isArray(data.colAligns) || data.colAligns.length !== cols) {
|
|
1398
1421
|
return false;
|
|
@@ -2602,6 +2625,7 @@ var codeWidgetFormat = {
|
|
|
2602
2625
|
var dividerFormat = {
|
|
2603
2626
|
name: "divider",
|
|
2604
2627
|
scope: "embed",
|
|
2628
|
+
blockLevel: true,
|
|
2605
2629
|
normalize(value) {
|
|
2606
2630
|
return !!value;
|
|
2607
2631
|
},
|
|
@@ -3223,6 +3247,26 @@ function resolveDocumentPresentation(presentation) {
|
|
|
3223
3247
|
listBlockIndentCm
|
|
3224
3248
|
};
|
|
3225
3249
|
}
|
|
3250
|
+
function documentMetadataToPresentation(metadata) {
|
|
3251
|
+
if (!metadata) return void 0;
|
|
3252
|
+
const presentation = {};
|
|
3253
|
+
if (typeof metadata.lineSpacing === "number") {
|
|
3254
|
+
presentation.lineSpacing = metadata.lineSpacing;
|
|
3255
|
+
}
|
|
3256
|
+
if (typeof metadata.paragraphSpacingBeforeEm === "number") {
|
|
3257
|
+
presentation.paragraphSpacingBeforeEm = metadata.paragraphSpacingBeforeEm;
|
|
3258
|
+
}
|
|
3259
|
+
if (typeof metadata.paragraphSpacingAfterEm === "number") {
|
|
3260
|
+
presentation.paragraphSpacingAfterEm = metadata.paragraphSpacingAfterEm;
|
|
3261
|
+
}
|
|
3262
|
+
if (typeof metadata.textIndentCm === "number") {
|
|
3263
|
+
presentation.textIndentCm = metadata.textIndentCm;
|
|
3264
|
+
}
|
|
3265
|
+
if (typeof metadata.listBlockIndentCm === "number") {
|
|
3266
|
+
presentation.listBlockIndentCm = metadata.listBlockIndentCm;
|
|
3267
|
+
}
|
|
3268
|
+
return Object.keys(presentation).length > 0 ? presentation : void 0;
|
|
3269
|
+
}
|
|
3226
3270
|
var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
3227
3271
|
function documentPresentationListWrapperStyleParts(resolved) {
|
|
3228
3272
|
if (!resolved?.listBlockIndentCm) return [];
|
|
@@ -3408,7 +3452,9 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3408
3452
|
const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
|
|
3409
3453
|
const blockHandlers = options.blockHandlers;
|
|
3410
3454
|
const anchorLinks = options.anchorLinks ?? false;
|
|
3411
|
-
const resolvedDocumentPresentation = resolveDocumentPresentation(
|
|
3455
|
+
const resolvedDocumentPresentation = resolveDocumentPresentation(
|
|
3456
|
+
options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
|
|
3457
|
+
);
|
|
3412
3458
|
let html = "";
|
|
3413
3459
|
let listStack = [];
|
|
3414
3460
|
let counters = [];
|
|
@@ -4046,7 +4092,13 @@ function htmlToDelta(html, options = {}) {
|
|
|
4046
4092
|
if (format.match) {
|
|
4047
4093
|
const result = format.match(node);
|
|
4048
4094
|
if (result != null) {
|
|
4095
|
+
if (format.blockLevel && !atLineStart) {
|
|
4096
|
+
context.pushNewline();
|
|
4097
|
+
}
|
|
4049
4098
|
context.pushEmbed({ [format.name]: result.value }, result.attributes);
|
|
4099
|
+
if (format.blockLevel) {
|
|
4100
|
+
context.pushNewline();
|
|
4101
|
+
}
|
|
4050
4102
|
return;
|
|
4051
4103
|
}
|
|
4052
4104
|
}
|
|
@@ -4061,6 +4113,9 @@ function htmlToDelta(html, options = {}) {
|
|
|
4061
4113
|
return;
|
|
4062
4114
|
}
|
|
4063
4115
|
if (tagName === "hr") {
|
|
4116
|
+
if (!atLineStart) {
|
|
4117
|
+
context.pushNewline();
|
|
4118
|
+
}
|
|
4064
4119
|
context.pushEmbed({ divider: true });
|
|
4065
4120
|
context.pushNewline();
|
|
4066
4121
|
return;
|
|
@@ -6180,6 +6235,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6180
6235
|
deltaToHtml,
|
|
6181
6236
|
deltaToMarkdown,
|
|
6182
6237
|
dividerFormat,
|
|
6238
|
+
documentMetadataToPresentation,
|
|
6183
6239
|
documentPresentationStyleParts,
|
|
6184
6240
|
escapeHtml,
|
|
6185
6241
|
extractBoxOpAttributes,
|