@scrider/formatter 1.8.7 → 1.10.0
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 +77 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +134 -2
- package/dist/index.d.ts +134 -2
- package/dist/index.js +71 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -44,6 +44,8 @@ __export(index_exports, {
|
|
|
44
44
|
SCRIDER_LINE_HEIGHT_KEY: () => SCRIDER_LINE_HEIGHT_KEY,
|
|
45
45
|
SCRIDER_MARGIN_AFTER_KEY: () => SCRIDER_MARGIN_AFTER_KEY,
|
|
46
46
|
SCRIDER_MARGIN_BEFORE_KEY: () => SCRIDER_MARGIN_BEFORE_KEY,
|
|
47
|
+
SCRIDER_TEXT_INDENT_KEY: () => SCRIDER_TEXT_INDENT_KEY,
|
|
48
|
+
TEXT_INDENT_BLOCK_TAGS: () => TEXT_INDENT_BLOCK_TAGS,
|
|
47
49
|
alertBlockHandler: () => alertBlockHandler,
|
|
48
50
|
alignFormat: () => alignFormat,
|
|
49
51
|
backgroundFormat: () => backgroundFormat,
|
|
@@ -53,6 +55,7 @@ __export(index_exports, {
|
|
|
53
55
|
blockMarginBeforeStyleParts: () => blockMarginBeforeStyleParts,
|
|
54
56
|
blockParagraphMarginStyleParts: () => blockParagraphMarginStyleParts,
|
|
55
57
|
blockPresentationStyleParts: () => blockPresentationStyleParts,
|
|
58
|
+
blockTextIndentStyleParts: () => blockTextIndentStyleParts,
|
|
56
59
|
blockquoteFormat: () => blockquoteFormat,
|
|
57
60
|
boldFormat: () => boldFormat,
|
|
58
61
|
boxBlockHandler: () => boxBlockHandler,
|
|
@@ -70,9 +73,11 @@ __export(index_exports, {
|
|
|
70
73
|
defaultEmbedFormats: () => defaultEmbedFormats,
|
|
71
74
|
defaultFormats: () => defaultFormats,
|
|
72
75
|
defaultInlineFormats: () => defaultInlineFormats,
|
|
76
|
+
deltaToDom: () => deltaToDom,
|
|
73
77
|
deltaToHtml: () => deltaToHtml,
|
|
74
78
|
deltaToMarkdown: () => deltaToMarkdown,
|
|
75
79
|
dividerFormat: () => dividerFormat,
|
|
80
|
+
documentMetadataToPresentation: () => documentMetadataToPresentation,
|
|
76
81
|
documentPresentationStyleParts: () => documentPresentationStyleParts,
|
|
77
82
|
escapeHtml: () => escapeHtml,
|
|
78
83
|
extractBoxOpAttributes: () => extractBoxOpAttributes,
|
|
@@ -111,6 +116,7 @@ __export(index_exports, {
|
|
|
111
116
|
parseScriderMarginBeforeEm: () => parseScriderMarginBeforeEm,
|
|
112
117
|
parseScriderMarginEm: () => parseScriderMarginEm,
|
|
113
118
|
preloadRemark: () => preloadRemark,
|
|
119
|
+
renderDelta: () => renderDelta,
|
|
114
120
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
115
121
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
116
122
|
sanitizeDelta: () => sanitizeDelta,
|
|
@@ -998,10 +1004,12 @@ function renderTableHostWrapperOpen(data, pretty) {
|
|
|
998
1004
|
attrs.push(`data-block-align="${escapeHtml(data.blockAlign)}"`);
|
|
999
1005
|
}
|
|
1000
1006
|
const styleParts = [];
|
|
1001
|
-
if (data.
|
|
1007
|
+
if (data.blockAlign === "justify" && !data.float) {
|
|
1008
|
+
styleParts.push("width: 100%");
|
|
1009
|
+
} else if (data.width != null && data.width > 0) {
|
|
1002
1010
|
styleParts.push(`width: ${Math.round(data.width)}px`);
|
|
1003
1011
|
styleParts.push("max-width: 100%");
|
|
1004
|
-
} else if (data.blockAlign
|
|
1012
|
+
} else if (data.blockAlign && !data.float) {
|
|
1005
1013
|
styleParts.push("width: 100%");
|
|
1006
1014
|
}
|
|
1007
1015
|
if (styleParts.length > 0) attrs.push(`style="${styleParts.join("; ")}"`);
|
|
@@ -2622,6 +2630,7 @@ var codeWidgetFormat = {
|
|
|
2622
2630
|
var dividerFormat = {
|
|
2623
2631
|
name: "divider",
|
|
2624
2632
|
scope: "embed",
|
|
2633
|
+
blockLevel: true,
|
|
2625
2634
|
normalize(value) {
|
|
2626
2635
|
return !!value;
|
|
2627
2636
|
},
|
|
@@ -3126,7 +3135,9 @@ function slugifyWithDedup(text, usedSlugs) {
|
|
|
3126
3135
|
var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
|
|
3127
3136
|
var SCRIDER_MARGIN_AFTER_KEY = "scrider-margin-after";
|
|
3128
3137
|
var SCRIDER_MARGIN_BEFORE_KEY = "scrider-margin-before";
|
|
3138
|
+
var SCRIDER_TEXT_INDENT_KEY = "scrider-text-indent";
|
|
3129
3139
|
var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
|
|
3140
|
+
var TEXT_INDENT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
3130
3141
|
var PARAGRAPH_SPACING_BLOCK_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
3131
3142
|
function parseScriderLineHeightMultiplier(value) {
|
|
3132
3143
|
const trimmed = value.trim();
|
|
@@ -3156,6 +3167,18 @@ function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
|
|
|
3156
3167
|
}
|
|
3157
3168
|
return [];
|
|
3158
3169
|
}
|
|
3170
|
+
function blockTextIndentStyleParts(tag, blockAttributes, resolved) {
|
|
3171
|
+
if (!TEXT_INDENT_BLOCK_TAGS.has(tag)) return [];
|
|
3172
|
+
const raw = blockAttributes?.[SCRIDER_TEXT_INDENT_KEY];
|
|
3173
|
+
if (typeof raw === "string") {
|
|
3174
|
+
const trimmed = raw.trim();
|
|
3175
|
+
if (trimmed) return [`text-indent:${trimmed}`];
|
|
3176
|
+
}
|
|
3177
|
+
if (resolved?.textIndentCm !== void 0) {
|
|
3178
|
+
return [`text-indent:${resolved.textIndentCm}cm`];
|
|
3179
|
+
}
|
|
3180
|
+
return [];
|
|
3181
|
+
}
|
|
3159
3182
|
function parseScriderMarginEm(value) {
|
|
3160
3183
|
const trimmed = value.trim();
|
|
3161
3184
|
if (!trimmed) return void 0;
|
|
@@ -3243,6 +3266,26 @@ function resolveDocumentPresentation(presentation) {
|
|
|
3243
3266
|
listBlockIndentCm
|
|
3244
3267
|
};
|
|
3245
3268
|
}
|
|
3269
|
+
function documentMetadataToPresentation(metadata) {
|
|
3270
|
+
if (!metadata) return void 0;
|
|
3271
|
+
const presentation = {};
|
|
3272
|
+
if (typeof metadata.lineSpacing === "number") {
|
|
3273
|
+
presentation.lineSpacing = metadata.lineSpacing;
|
|
3274
|
+
}
|
|
3275
|
+
if (typeof metadata.paragraphSpacingBeforeEm === "number") {
|
|
3276
|
+
presentation.paragraphSpacingBeforeEm = metadata.paragraphSpacingBeforeEm;
|
|
3277
|
+
}
|
|
3278
|
+
if (typeof metadata.paragraphSpacingAfterEm === "number") {
|
|
3279
|
+
presentation.paragraphSpacingAfterEm = metadata.paragraphSpacingAfterEm;
|
|
3280
|
+
}
|
|
3281
|
+
if (typeof metadata.textIndentCm === "number") {
|
|
3282
|
+
presentation.textIndentCm = metadata.textIndentCm;
|
|
3283
|
+
}
|
|
3284
|
+
if (typeof metadata.listBlockIndentCm === "number") {
|
|
3285
|
+
presentation.listBlockIndentCm = metadata.listBlockIndentCm;
|
|
3286
|
+
}
|
|
3287
|
+
return Object.keys(presentation).length > 0 ? presentation : void 0;
|
|
3288
|
+
}
|
|
3246
3289
|
var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
3247
3290
|
function documentPresentationListWrapperStyleParts(resolved) {
|
|
3248
3291
|
if (!resolved?.listBlockIndentCm) return [];
|
|
@@ -3260,7 +3303,7 @@ function blockPresentationStyleParts(tag, blockAttributes, resolved) {
|
|
|
3260
3303
|
return [
|
|
3261
3304
|
...blockLineHeightStyleParts(tag, blockAttributes, resolved),
|
|
3262
3305
|
...blockParagraphMarginStyleParts(tag, blockAttributes, resolved),
|
|
3263
|
-
...
|
|
3306
|
+
...blockTextIndentStyleParts(tag, blockAttributes, resolved)
|
|
3264
3307
|
];
|
|
3265
3308
|
}
|
|
3266
3309
|
function joinStyleParts(parts) {
|
|
@@ -3428,7 +3471,9 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3428
3471
|
const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
|
|
3429
3472
|
const blockHandlers = options.blockHandlers;
|
|
3430
3473
|
const anchorLinks = options.anchorLinks ?? false;
|
|
3431
|
-
const resolvedDocumentPresentation = resolveDocumentPresentation(
|
|
3474
|
+
const resolvedDocumentPresentation = resolveDocumentPresentation(
|
|
3475
|
+
options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
|
|
3476
|
+
);
|
|
3432
3477
|
let html = "";
|
|
3433
3478
|
let listStack = [];
|
|
3434
3479
|
let counters = [];
|
|
@@ -3542,6 +3587,19 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3542
3587
|
}
|
|
3543
3588
|
return html;
|
|
3544
3589
|
}
|
|
3590
|
+
function stripPresentationForEditor(options) {
|
|
3591
|
+
const rest = { ...options };
|
|
3592
|
+
delete rest.documentPresentation;
|
|
3593
|
+
delete rest.documentMetadata;
|
|
3594
|
+
delete rest.tablePresentation;
|
|
3595
|
+
return rest;
|
|
3596
|
+
}
|
|
3597
|
+
function renderDelta(delta, profile, options = {}) {
|
|
3598
|
+
return profile === "editor" ? deltaToHtml(delta, stripPresentationForEditor(options)) : deltaToHtml(delta, options);
|
|
3599
|
+
}
|
|
3600
|
+
function deltaToDom(delta, options = {}) {
|
|
3601
|
+
return renderDelta(delta, "editor", options);
|
|
3602
|
+
}
|
|
3545
3603
|
function getIndent(level) {
|
|
3546
3604
|
return " ".repeat(level);
|
|
3547
3605
|
}
|
|
@@ -4066,7 +4124,13 @@ function htmlToDelta(html, options = {}) {
|
|
|
4066
4124
|
if (format.match) {
|
|
4067
4125
|
const result = format.match(node);
|
|
4068
4126
|
if (result != null) {
|
|
4127
|
+
if (format.blockLevel && !atLineStart) {
|
|
4128
|
+
context.pushNewline();
|
|
4129
|
+
}
|
|
4069
4130
|
context.pushEmbed({ [format.name]: result.value }, result.attributes);
|
|
4131
|
+
if (format.blockLevel) {
|
|
4132
|
+
context.pushNewline();
|
|
4133
|
+
}
|
|
4070
4134
|
return;
|
|
4071
4135
|
}
|
|
4072
4136
|
}
|
|
@@ -4081,6 +4145,9 @@ function htmlToDelta(html, options = {}) {
|
|
|
4081
4145
|
return;
|
|
4082
4146
|
}
|
|
4083
4147
|
if (tagName === "hr") {
|
|
4148
|
+
if (!atLineStart) {
|
|
4149
|
+
context.pushNewline();
|
|
4150
|
+
}
|
|
4084
4151
|
context.pushEmbed({ divider: true });
|
|
4085
4152
|
context.pushNewline();
|
|
4086
4153
|
return;
|
|
@@ -6171,6 +6238,8 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6171
6238
|
SCRIDER_LINE_HEIGHT_KEY,
|
|
6172
6239
|
SCRIDER_MARGIN_AFTER_KEY,
|
|
6173
6240
|
SCRIDER_MARGIN_BEFORE_KEY,
|
|
6241
|
+
SCRIDER_TEXT_INDENT_KEY,
|
|
6242
|
+
TEXT_INDENT_BLOCK_TAGS,
|
|
6174
6243
|
alertBlockHandler,
|
|
6175
6244
|
alignFormat,
|
|
6176
6245
|
backgroundFormat,
|
|
@@ -6180,6 +6249,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6180
6249
|
blockMarginBeforeStyleParts,
|
|
6181
6250
|
blockParagraphMarginStyleParts,
|
|
6182
6251
|
blockPresentationStyleParts,
|
|
6252
|
+
blockTextIndentStyleParts,
|
|
6183
6253
|
blockquoteFormat,
|
|
6184
6254
|
boldFormat,
|
|
6185
6255
|
boxBlockHandler,
|
|
@@ -6197,9 +6267,11 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6197
6267
|
defaultEmbedFormats,
|
|
6198
6268
|
defaultFormats,
|
|
6199
6269
|
defaultInlineFormats,
|
|
6270
|
+
deltaToDom,
|
|
6200
6271
|
deltaToHtml,
|
|
6201
6272
|
deltaToMarkdown,
|
|
6202
6273
|
dividerFormat,
|
|
6274
|
+
documentMetadataToPresentation,
|
|
6203
6275
|
documentPresentationStyleParts,
|
|
6204
6276
|
escapeHtml,
|
|
6205
6277
|
extractBoxOpAttributes,
|
|
@@ -6238,6 +6310,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6238
6310
|
parseScriderMarginBeforeEm,
|
|
6239
6311
|
parseScriderMarginEm,
|
|
6240
6312
|
preloadRemark,
|
|
6313
|
+
renderDelta,
|
|
6241
6314
|
resolveDocumentPresentation,
|
|
6242
6315
|
resolveTablePresentation,
|
|
6243
6316
|
sanitizeDelta,
|