@scrider/formatter 1.4.2 → 1.4.3
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 +42 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -39,13 +39,16 @@ __export(index_exports, {
|
|
|
39
39
|
LINE_HEIGHT_BLOCK_TAGS: () => LINE_HEIGHT_BLOCK_TAGS,
|
|
40
40
|
NODE_TYPE: () => NODE_TYPE,
|
|
41
41
|
NodeDOMAdapter: () => NodeDOMAdapter,
|
|
42
|
+
PARAGRAPH_SPACING_BLOCK_TAGS: () => PARAGRAPH_SPACING_BLOCK_TAGS,
|
|
42
43
|
Registry: () => Registry,
|
|
43
44
|
SCRIDER_LINE_HEIGHT_KEY: () => SCRIDER_LINE_HEIGHT_KEY,
|
|
45
|
+
SCRIDER_MARGIN_AFTER_KEY: () => SCRIDER_MARGIN_AFTER_KEY,
|
|
44
46
|
alertBlockHandler: () => alertBlockHandler,
|
|
45
47
|
alignFormat: () => alignFormat,
|
|
46
48
|
backgroundFormat: () => backgroundFormat,
|
|
47
49
|
blockFormat: () => blockFormat,
|
|
48
50
|
blockLineHeightStyleParts: () => blockLineHeightStyleParts,
|
|
51
|
+
blockMarginAfterStyleParts: () => blockMarginAfterStyleParts,
|
|
49
52
|
blockPresentationStyleParts: () => blockPresentationStyleParts,
|
|
50
53
|
blockquoteFormat: () => blockquoteFormat,
|
|
51
54
|
boldFormat: () => boldFormat,
|
|
@@ -98,6 +101,7 @@ __export(index_exports, {
|
|
|
98
101
|
nodeAdapter: () => nodeAdapter,
|
|
99
102
|
normalizeDelta: () => normalizeDelta,
|
|
100
103
|
parseScriderLineHeightMultiplier: () => parseScriderLineHeightMultiplier,
|
|
104
|
+
parseScriderMarginAfterEm: () => parseScriderMarginAfterEm,
|
|
101
105
|
preloadRemark: () => preloadRemark,
|
|
102
106
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
103
107
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
@@ -2610,7 +2614,9 @@ function slugifyWithDedup(text, usedSlugs) {
|
|
|
2610
2614
|
|
|
2611
2615
|
// src/conversion/html/block-presentation.ts
|
|
2612
2616
|
var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
|
|
2617
|
+
var SCRIDER_MARGIN_AFTER_KEY = "scrider-margin-after";
|
|
2613
2618
|
var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
|
|
2619
|
+
var PARAGRAPH_SPACING_BLOCK_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
2614
2620
|
function parseScriderLineHeightMultiplier(value) {
|
|
2615
2621
|
const trimmed = value.trim();
|
|
2616
2622
|
if (!trimmed) return void 0;
|
|
@@ -2639,6 +2645,34 @@ function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
|
|
|
2639
2645
|
}
|
|
2640
2646
|
return [];
|
|
2641
2647
|
}
|
|
2648
|
+
function parseScriderMarginAfterEm(value) {
|
|
2649
|
+
const trimmed = value.trim();
|
|
2650
|
+
if (!trimmed) return void 0;
|
|
2651
|
+
const emMatch = trimmed.match(/^(-?\d+(?:\.\d+)?)\s*em$/i);
|
|
2652
|
+
if (emMatch) {
|
|
2653
|
+
const n2 = Number.parseFloat(emMatch[1]);
|
|
2654
|
+
if (Number.isFinite(n2) && n2 >= 0) return n2;
|
|
2655
|
+
return void 0;
|
|
2656
|
+
}
|
|
2657
|
+
const n = Number.parseFloat(trimmed);
|
|
2658
|
+
if (Number.isFinite(n) && n >= 0) return n;
|
|
2659
|
+
return void 0;
|
|
2660
|
+
}
|
|
2661
|
+
function marginAfterStyleParts(em) {
|
|
2662
|
+
return [`margin-top:0`, `margin-bottom:${em}em`];
|
|
2663
|
+
}
|
|
2664
|
+
function blockMarginAfterStyleParts(tag, blockAttributes, resolved) {
|
|
2665
|
+
if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
|
|
2666
|
+
const raw = blockAttributes?.[SCRIDER_MARGIN_AFTER_KEY];
|
|
2667
|
+
if (typeof raw === "string") {
|
|
2668
|
+
const fromBlock = parseScriderMarginAfterEm(raw);
|
|
2669
|
+
if (fromBlock !== void 0) return marginAfterStyleParts(fromBlock);
|
|
2670
|
+
}
|
|
2671
|
+
if (resolved?.paragraphSpacingAfterEm !== void 0) {
|
|
2672
|
+
return marginAfterStyleParts(resolved.paragraphSpacingAfterEm);
|
|
2673
|
+
}
|
|
2674
|
+
return [];
|
|
2675
|
+
}
|
|
2642
2676
|
|
|
2643
2677
|
// src/conversion/html/document-presentation.ts
|
|
2644
2678
|
function resolveDocumentPresentation(presentation) {
|
|
@@ -2646,10 +2680,11 @@ function resolveDocumentPresentation(presentation) {
|
|
|
2646
2680
|
const lineSpacing = typeof presentation.lineSpacing === "number" && presentation.lineSpacing > 0 ? presentation.lineSpacing : void 0;
|
|
2647
2681
|
const textIndentCm = typeof presentation.textIndentCm === "number" && presentation.textIndentCm > 0 ? presentation.textIndentCm : void 0;
|
|
2648
2682
|
const listBlockIndentCm = typeof presentation.listBlockIndentCm === "number" && presentation.listBlockIndentCm > 0 ? presentation.listBlockIndentCm : void 0;
|
|
2649
|
-
|
|
2683
|
+
const paragraphSpacingAfterEm = typeof presentation.paragraphSpacingAfterEm === "number" && Number.isFinite(presentation.paragraphSpacingAfterEm) && presentation.paragraphSpacingAfterEm >= 0 ? presentation.paragraphSpacingAfterEm : void 0;
|
|
2684
|
+
if (lineSpacing === void 0 && paragraphSpacingAfterEm === void 0 && textIndentCm === void 0 && listBlockIndentCm === void 0) {
|
|
2650
2685
|
return void 0;
|
|
2651
2686
|
}
|
|
2652
|
-
return { lineSpacing, textIndentCm, listBlockIndentCm };
|
|
2687
|
+
return { lineSpacing, paragraphSpacingAfterEm, textIndentCm, listBlockIndentCm };
|
|
2653
2688
|
}
|
|
2654
2689
|
var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
2655
2690
|
function documentPresentationListWrapperStyleParts(resolved) {
|
|
@@ -2667,6 +2702,7 @@ function documentPresentationStyleParts(tag, resolved) {
|
|
|
2667
2702
|
function blockPresentationStyleParts(tag, blockAttributes, resolved) {
|
|
2668
2703
|
return [
|
|
2669
2704
|
...blockLineHeightStyleParts(tag, blockAttributes, resolved),
|
|
2705
|
+
...blockMarginAfterStyleParts(tag, blockAttributes, resolved),
|
|
2670
2706
|
...documentPresentationStyleParts(tag, resolved)
|
|
2671
2707
|
];
|
|
2672
2708
|
}
|
|
@@ -5302,13 +5338,16 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5302
5338
|
LINE_HEIGHT_BLOCK_TAGS,
|
|
5303
5339
|
NODE_TYPE,
|
|
5304
5340
|
NodeDOMAdapter,
|
|
5341
|
+
PARAGRAPH_SPACING_BLOCK_TAGS,
|
|
5305
5342
|
Registry,
|
|
5306
5343
|
SCRIDER_LINE_HEIGHT_KEY,
|
|
5344
|
+
SCRIDER_MARGIN_AFTER_KEY,
|
|
5307
5345
|
alertBlockHandler,
|
|
5308
5346
|
alignFormat,
|
|
5309
5347
|
backgroundFormat,
|
|
5310
5348
|
blockFormat,
|
|
5311
5349
|
blockLineHeightStyleParts,
|
|
5350
|
+
blockMarginAfterStyleParts,
|
|
5312
5351
|
blockPresentationStyleParts,
|
|
5313
5352
|
blockquoteFormat,
|
|
5314
5353
|
boldFormat,
|
|
@@ -5361,6 +5400,7 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5361
5400
|
nodeAdapter,
|
|
5362
5401
|
normalizeDelta,
|
|
5363
5402
|
parseScriderLineHeightMultiplier,
|
|
5403
|
+
parseScriderMarginAfterEm,
|
|
5364
5404
|
preloadRemark,
|
|
5365
5405
|
resolveDocumentPresentation,
|
|
5366
5406
|
resolveTablePresentation,
|