@scrider/formatter 1.4.1 → 1.4.2
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 +57 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -4
- package/dist/index.d.ts +22 -4
- package/dist/index.js +52 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,13 +36,17 @@ __export(index_exports, {
|
|
|
36
36
|
BOX_OVERFLOW_VALUES: () => BOX_OVERFLOW_VALUES,
|
|
37
37
|
BlockHandlerRegistry: () => BlockHandlerRegistry,
|
|
38
38
|
BrowserDOMAdapter: () => BrowserDOMAdapter,
|
|
39
|
+
LINE_HEIGHT_BLOCK_TAGS: () => LINE_HEIGHT_BLOCK_TAGS,
|
|
39
40
|
NODE_TYPE: () => NODE_TYPE,
|
|
40
41
|
NodeDOMAdapter: () => NodeDOMAdapter,
|
|
41
42
|
Registry: () => Registry,
|
|
43
|
+
SCRIDER_LINE_HEIGHT_KEY: () => SCRIDER_LINE_HEIGHT_KEY,
|
|
42
44
|
alertBlockHandler: () => alertBlockHandler,
|
|
43
45
|
alignFormat: () => alignFormat,
|
|
44
46
|
backgroundFormat: () => backgroundFormat,
|
|
45
47
|
blockFormat: () => blockFormat,
|
|
48
|
+
blockLineHeightStyleParts: () => blockLineHeightStyleParts,
|
|
49
|
+
blockPresentationStyleParts: () => blockPresentationStyleParts,
|
|
46
50
|
blockquoteFormat: () => blockquoteFormat,
|
|
47
51
|
boldFormat: () => boldFormat,
|
|
48
52
|
boxBlockHandler: () => boxBlockHandler,
|
|
@@ -93,6 +97,7 @@ __export(index_exports, {
|
|
|
93
97
|
markdownToDeltaSync: () => markdownToDeltaSync,
|
|
94
98
|
nodeAdapter: () => nodeAdapter,
|
|
95
99
|
normalizeDelta: () => normalizeDelta,
|
|
100
|
+
parseScriderLineHeightMultiplier: () => parseScriderLineHeightMultiplier,
|
|
96
101
|
preloadRemark: () => preloadRemark,
|
|
97
102
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
98
103
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
@@ -2603,6 +2608,38 @@ function slugifyWithDedup(text, usedSlugs) {
|
|
|
2603
2608
|
return `${base}-${count}`;
|
|
2604
2609
|
}
|
|
2605
2610
|
|
|
2611
|
+
// src/conversion/html/block-presentation.ts
|
|
2612
|
+
var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
|
|
2613
|
+
var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
|
|
2614
|
+
function parseScriderLineHeightMultiplier(value) {
|
|
2615
|
+
const trimmed = value.trim();
|
|
2616
|
+
if (!trimmed) return void 0;
|
|
2617
|
+
if (trimmed.endsWith("%")) {
|
|
2618
|
+
const pct = Number.parseFloat(trimmed.slice(0, -1));
|
|
2619
|
+
if (Number.isFinite(pct) && pct > 0) return pct / 100;
|
|
2620
|
+
return void 0;
|
|
2621
|
+
}
|
|
2622
|
+
const n = Number.parseFloat(trimmed);
|
|
2623
|
+
if (Number.isFinite(n) && n > 0) return n;
|
|
2624
|
+
return void 0;
|
|
2625
|
+
}
|
|
2626
|
+
function lineHeightStyleParts(multiplier) {
|
|
2627
|
+
const pct = Math.round(multiplier * 100);
|
|
2628
|
+
return [`line-height:${multiplier}`, `mso-line-height-alt:${pct}%`];
|
|
2629
|
+
}
|
|
2630
|
+
function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
|
|
2631
|
+
if (!LINE_HEIGHT_BLOCK_TAGS.has(tag)) return [];
|
|
2632
|
+
const raw = blockAttributes?.[SCRIDER_LINE_HEIGHT_KEY];
|
|
2633
|
+
if (typeof raw === "string") {
|
|
2634
|
+
const fromBlock = parseScriderLineHeightMultiplier(raw);
|
|
2635
|
+
if (fromBlock !== void 0) return lineHeightStyleParts(fromBlock);
|
|
2636
|
+
}
|
|
2637
|
+
if (resolved?.lineSpacing !== void 0) {
|
|
2638
|
+
return lineHeightStyleParts(resolved.lineSpacing);
|
|
2639
|
+
}
|
|
2640
|
+
return [];
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2606
2643
|
// src/conversion/html/document-presentation.ts
|
|
2607
2644
|
function resolveDocumentPresentation(presentation) {
|
|
2608
2645
|
if (!presentation) return void 0;
|
|
@@ -2614,28 +2651,25 @@ function resolveDocumentPresentation(presentation) {
|
|
|
2614
2651
|
}
|
|
2615
2652
|
return { lineSpacing, textIndentCm, listBlockIndentCm };
|
|
2616
2653
|
}
|
|
2617
|
-
var LINE_HEIGHT_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
|
|
2618
2654
|
var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
2619
2655
|
function documentPresentationListWrapperStyleParts(resolved) {
|
|
2620
2656
|
if (!resolved?.listBlockIndentCm) return [];
|
|
2621
|
-
return [
|
|
2622
|
-
`padding-left:1.25em`,
|
|
2623
|
-
`margin-left:${resolved.listBlockIndentCm}cm`
|
|
2624
|
-
];
|
|
2657
|
+
return [`padding-left:1.25em`, `margin-left:${resolved.listBlockIndentCm}cm`];
|
|
2625
2658
|
}
|
|
2626
2659
|
function documentPresentationStyleParts(tag, resolved) {
|
|
2627
2660
|
if (!resolved) return [];
|
|
2628
2661
|
const parts = [];
|
|
2629
|
-
if (resolved.lineSpacing !== void 0 && LINE_HEIGHT_TAGS.has(tag)) {
|
|
2630
|
-
const pct = Math.round(resolved.lineSpacing * 100);
|
|
2631
|
-
parts.push(`line-height:${resolved.lineSpacing}`);
|
|
2632
|
-
parts.push(`mso-line-height-alt:${pct}%`);
|
|
2633
|
-
}
|
|
2634
2662
|
if (resolved.textIndentCm !== void 0 && TEXT_INDENT_TAGS.has(tag)) {
|
|
2635
2663
|
parts.push(`text-indent:${resolved.textIndentCm}cm`);
|
|
2636
2664
|
}
|
|
2637
2665
|
return parts;
|
|
2638
2666
|
}
|
|
2667
|
+
function blockPresentationStyleParts(tag, blockAttributes, resolved) {
|
|
2668
|
+
return [
|
|
2669
|
+
...blockLineHeightStyleParts(tag, blockAttributes, resolved),
|
|
2670
|
+
...documentPresentationStyleParts(tag, resolved)
|
|
2671
|
+
];
|
|
2672
|
+
}
|
|
2639
2673
|
function joinStyleParts(parts) {
|
|
2640
2674
|
return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
|
|
2641
2675
|
}
|
|
@@ -2782,6 +2816,7 @@ function deltaToHtml(delta, options = {}) {
|
|
|
2782
2816
|
html += renderListItem(
|
|
2783
2817
|
content,
|
|
2784
2818
|
listItemAttrs,
|
|
2819
|
+
line.attributes,
|
|
2785
2820
|
pretty,
|
|
2786
2821
|
indentLevel,
|
|
2787
2822
|
hierarchicalNumber,
|
|
@@ -3101,17 +3136,14 @@ function getListItemAttributes(attributes) {
|
|
|
3101
3136
|
}
|
|
3102
3137
|
return "";
|
|
3103
3138
|
}
|
|
3104
|
-
function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
|
|
3139
|
+
function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
|
|
3105
3140
|
const indent = pretty ? getIndent(indentLevel) : "";
|
|
3106
3141
|
const innerContent = content || "<br>";
|
|
3107
3142
|
let fullAttrs = attrs;
|
|
3108
3143
|
if (hierarchicalNumber) {
|
|
3109
3144
|
fullAttrs += ` data-number="${hierarchicalNumber}"`;
|
|
3110
3145
|
}
|
|
3111
|
-
|
|
3112
|
-
documentPresentationStyleParts("li", resolvedDocumentPresentation)
|
|
3113
|
-
);
|
|
3114
|
-
fullAttrs += styleAttr;
|
|
3146
|
+
fullAttrs += getBlockStyleAttribute("li", blockAttributes, resolvedDocumentPresentation);
|
|
3115
3147
|
const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
|
|
3116
3148
|
return pretty ? html + "\n" : html;
|
|
3117
3149
|
}
|
|
@@ -3123,7 +3155,11 @@ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPrese
|
|
|
3123
3155
|
return pretty ? html + "\n" : html;
|
|
3124
3156
|
}
|
|
3125
3157
|
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
|
|
3126
|
-
const styles =
|
|
3158
|
+
const styles = blockPresentationStyleParts(
|
|
3159
|
+
tag,
|
|
3160
|
+
attributes,
|
|
3161
|
+
resolvedDocumentPresentation
|
|
3162
|
+
);
|
|
3127
3163
|
if (attributes) {
|
|
3128
3164
|
const alignVal = attributes.align;
|
|
3129
3165
|
if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
|
|
@@ -5263,13 +5299,17 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5263
5299
|
BOX_OVERFLOW_VALUES,
|
|
5264
5300
|
BlockHandlerRegistry,
|
|
5265
5301
|
BrowserDOMAdapter,
|
|
5302
|
+
LINE_HEIGHT_BLOCK_TAGS,
|
|
5266
5303
|
NODE_TYPE,
|
|
5267
5304
|
NodeDOMAdapter,
|
|
5268
5305
|
Registry,
|
|
5306
|
+
SCRIDER_LINE_HEIGHT_KEY,
|
|
5269
5307
|
alertBlockHandler,
|
|
5270
5308
|
alignFormat,
|
|
5271
5309
|
backgroundFormat,
|
|
5272
5310
|
blockFormat,
|
|
5311
|
+
blockLineHeightStyleParts,
|
|
5312
|
+
blockPresentationStyleParts,
|
|
5273
5313
|
blockquoteFormat,
|
|
5274
5314
|
boldFormat,
|
|
5275
5315
|
boxBlockHandler,
|
|
@@ -5320,6 +5360,7 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5320
5360
|
markdownToDeltaSync,
|
|
5321
5361
|
nodeAdapter,
|
|
5322
5362
|
normalizeDelta,
|
|
5363
|
+
parseScriderLineHeightMultiplier,
|
|
5323
5364
|
preloadRemark,
|
|
5324
5365
|
resolveDocumentPresentation,
|
|
5325
5366
|
resolveTablePresentation,
|