@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.d.cts
CHANGED
|
@@ -482,6 +482,8 @@ declare class BlockHandlerRegistry {
|
|
|
482
482
|
|
|
483
483
|
/** Block-level float on extended table host (4.2.10). */
|
|
484
484
|
type TableBlockFloat = 'left' | 'center' | 'right';
|
|
485
|
+
/** Block position when width is narrower than the line (margin-based, no float). */
|
|
486
|
+
type TableBlockAlign = 'left' | 'center' | 'right' | 'justify';
|
|
485
487
|
/**
|
|
486
488
|
* Column alignment options (GFM column-level subset).
|
|
487
489
|
*/
|
|
@@ -531,6 +533,8 @@ interface TableBlockData {
|
|
|
531
533
|
width?: number;
|
|
532
534
|
/** Block-level float on host wrapper (4.2.10). */
|
|
533
535
|
float?: TableBlockFloat;
|
|
536
|
+
/** Block position when width is set (margin-based, no float). */
|
|
537
|
+
blockAlign?: TableBlockAlign;
|
|
534
538
|
/** Column alignments */
|
|
535
539
|
colAligns?: (CellAlign | null)[];
|
|
536
540
|
/** Cells indexed by "row:col" */
|
package/dist/index.d.ts
CHANGED
|
@@ -482,6 +482,8 @@ declare class BlockHandlerRegistry {
|
|
|
482
482
|
|
|
483
483
|
/** Block-level float on extended table host (4.2.10). */
|
|
484
484
|
type TableBlockFloat = 'left' | 'center' | 'right';
|
|
485
|
+
/** Block position when width is narrower than the line (margin-based, no float). */
|
|
486
|
+
type TableBlockAlign = 'left' | 'center' | 'right' | 'justify';
|
|
485
487
|
/**
|
|
486
488
|
* Column alignment options (GFM column-level subset).
|
|
487
489
|
*/
|
|
@@ -531,6 +533,8 @@ interface TableBlockData {
|
|
|
531
533
|
width?: number;
|
|
532
534
|
/** Block-level float on host wrapper (4.2.10). */
|
|
533
535
|
float?: TableBlockFloat;
|
|
536
|
+
/** Block position when width is set (margin-based, no float). */
|
|
537
|
+
blockAlign?: TableBlockAlign;
|
|
534
538
|
/** Column alignments */
|
|
535
539
|
colAligns?: (CellAlign | null)[];
|
|
536
540
|
/** Cells indexed by "row:col" */
|
package/dist/index.js
CHANGED
|
@@ -627,6 +627,7 @@ function toCodeWidgetEmbedUrl(url) {
|
|
|
627
627
|
var EXT_TABLE_HOST_ATTR = "data-scrider-ext-table";
|
|
628
628
|
var EXT_TABLE_HOST_CLASS = "scrider-ext-table-host";
|
|
629
629
|
var VALID_TABLE_BLOCK_FLOATS = ["left", "center", "right"];
|
|
630
|
+
var VALID_TABLE_BLOCK_ALIGNS = ["left", "center", "right", "justify"];
|
|
630
631
|
var VALID_CELL_HORIZONTAL_ALIGNS = [
|
|
631
632
|
"left",
|
|
632
633
|
"center",
|
|
@@ -830,6 +831,12 @@ function parseTableBlockFloat(value) {
|
|
|
830
831
|
if (value === "left" || value === "center" || value === "right") return value;
|
|
831
832
|
return void 0;
|
|
832
833
|
}
|
|
834
|
+
function parseTableBlockAlign(value) {
|
|
835
|
+
if (value === "left" || value === "center" || value === "right" || value === "justify") {
|
|
836
|
+
return value;
|
|
837
|
+
}
|
|
838
|
+
return void 0;
|
|
839
|
+
}
|
|
833
840
|
function extractHostBlockWidthPx(host) {
|
|
834
841
|
const style = host.getAttribute("style") || "";
|
|
835
842
|
const widthMatch = style.match(/(?:^|;\s*)width:\s*([\d.]+)px/i);
|
|
@@ -840,25 +847,32 @@ function extractHostBlockWidthPx(host) {
|
|
|
840
847
|
}
|
|
841
848
|
function enrichTableBlockFromHost(data, host) {
|
|
842
849
|
const float = parseTableBlockFloat(host.getAttribute("data-float"));
|
|
850
|
+
const blockAlign = parseTableBlockAlign(host.getAttribute("data-block-align"));
|
|
843
851
|
const width = extractHostBlockWidthPx(host);
|
|
844
|
-
if (float == null && width == null) return data;
|
|
852
|
+
if (float == null && blockAlign == null && width == null) return data;
|
|
845
853
|
const next = { ...data };
|
|
846
854
|
if (float != null) next.float = float;
|
|
855
|
+
if (blockAlign != null && float == null) next.blockAlign = blockAlign;
|
|
847
856
|
if (width != null) next.width = width;
|
|
848
857
|
return next;
|
|
849
858
|
}
|
|
850
859
|
function tableNeedsHostWrapper(data) {
|
|
851
|
-
return data.float != null && VALID_TABLE_BLOCK_FLOATS.includes(data.float) || data.width != null && data.width > 0;
|
|
860
|
+
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);
|
|
852
861
|
}
|
|
853
862
|
function renderTableHostWrapperOpen(data, pretty) {
|
|
854
863
|
const nl = pretty ? "\n" : "";
|
|
855
864
|
const ind = pretty ? " " : "";
|
|
856
865
|
const attrs = [`class="${EXT_TABLE_HOST_CLASS}"`, EXT_TABLE_HOST_ATTR];
|
|
857
866
|
if (data.float) attrs.push(`data-float="${escapeHtml(data.float)}"`);
|
|
867
|
+
if (data.blockAlign && !data.float) {
|
|
868
|
+
attrs.push(`data-block-align="${escapeHtml(data.blockAlign)}"`);
|
|
869
|
+
}
|
|
858
870
|
const styleParts = [];
|
|
859
871
|
if (data.width != null && data.width > 0) {
|
|
860
872
|
styleParts.push(`width: ${Math.round(data.width)}px`);
|
|
861
873
|
styleParts.push("max-width: 100%");
|
|
874
|
+
} else if (data.blockAlign === "justify" && !data.float) {
|
|
875
|
+
styleParts.push("width: 100%");
|
|
862
876
|
}
|
|
863
877
|
if (styleParts.length > 0) attrs.push(`style="${styleParts.join("; ")}"`);
|
|
864
878
|
return `<div ${attrs.join(" ")}>${nl}${ind}`;
|
|
@@ -879,6 +893,9 @@ function isGfmCompatible(data) {
|
|
|
879
893
|
if (data.float != null) {
|
|
880
894
|
return false;
|
|
881
895
|
}
|
|
896
|
+
if (data.blockAlign != null) {
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
882
899
|
for (const cell of Object.values(data.cells)) {
|
|
883
900
|
if (cell !== null && cell.align !== void 0) return false;
|
|
884
901
|
}
|
|
@@ -1263,6 +1280,9 @@ var tableBlockHandler = {
|
|
|
1263
1280
|
if (data.float !== void 0 && !VALID_TABLE_BLOCK_FLOATS.includes(data.float)) {
|
|
1264
1281
|
return false;
|
|
1265
1282
|
}
|
|
1283
|
+
if (data.blockAlign !== void 0 && !VALID_TABLE_BLOCK_ALIGNS.includes(data.blockAlign)) {
|
|
1284
|
+
return false;
|
|
1285
|
+
}
|
|
1266
1286
|
if (data.colAligns !== void 0) {
|
|
1267
1287
|
if (!Array.isArray(data.colAligns) || data.colAligns.length !== cols) {
|
|
1268
1288
|
return false;
|