@scrider/formatter 1.10.0 → 1.10.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 +117 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -58
- package/dist/index.d.ts +110 -58
- package/dist/index.js +114 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -459,9 +459,13 @@ var EMBED_RENDERERS = {
|
|
|
459
459
|
const embedSrc = toCodeWidgetEmbedUrl(src);
|
|
460
460
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
461
461
|
},
|
|
462
|
+
// `data-scrider-embed` marks this span as 1 Delta char for DomBridge before
|
|
463
|
+
// KaTeX post-render replaces the text body with a `.katex` subtree. Without
|
|
464
|
+
// the marker, DomBridge counts the raw LaTeX length and drifts indices for
|
|
465
|
+
// everything after the formula (e.g. Simple Table chrome probe fails).
|
|
462
466
|
formula: (value) => {
|
|
463
467
|
const latex = typeof value === "string" ? value : "";
|
|
464
|
-
return `<span class="formula" data-formula="${escapeHtml(latex)}">${escapeHtml(latex)}</span>`;
|
|
468
|
+
return `<span class="formula" data-formula="${escapeHtml(latex)}" data-scrider-embed>${escapeHtml(latex)}</span>`;
|
|
465
469
|
},
|
|
466
470
|
diagram: (value) => {
|
|
467
471
|
const source = typeof value === "string" ? value : "";
|
|
@@ -2587,7 +2591,7 @@ var formulaFormat = {
|
|
|
2587
2591
|
},
|
|
2588
2592
|
render(value) {
|
|
2589
2593
|
const latex = typeof value === "string" ? value : "";
|
|
2590
|
-
return `<span class="formula" data-formula="${escapeHtml(latex)}">${escapeHtml(latex)}</span>`;
|
|
2594
|
+
return `<span class="formula" data-formula="${escapeHtml(latex)}" data-scrider-embed>${escapeHtml(latex)}</span>`;
|
|
2591
2595
|
},
|
|
2592
2596
|
match(element) {
|
|
2593
2597
|
if (element.tagName.toLowerCase() !== "span") return null;
|
|
@@ -3174,6 +3178,90 @@ function joinStyleParts(parts) {
|
|
|
3174
3178
|
return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
|
|
3175
3179
|
}
|
|
3176
3180
|
|
|
3181
|
+
// src/conversion/html/heading-presentation.ts
|
|
3182
|
+
var HEADER_SIZE_PRESETS = Object.freeze({
|
|
3183
|
+
scrider: Object.freeze({
|
|
3184
|
+
1: "32pt",
|
|
3185
|
+
2: "24pt",
|
|
3186
|
+
3: "20pt",
|
|
3187
|
+
4: "18pt",
|
|
3188
|
+
5: "16pt",
|
|
3189
|
+
6: "14pt"
|
|
3190
|
+
}),
|
|
3191
|
+
google: Object.freeze({
|
|
3192
|
+
1: "26pt",
|
|
3193
|
+
2: "20pt",
|
|
3194
|
+
3: "16pt",
|
|
3195
|
+
4: "14pt",
|
|
3196
|
+
5: "12pt",
|
|
3197
|
+
6: "11pt"
|
|
3198
|
+
}),
|
|
3199
|
+
word: Object.freeze({
|
|
3200
|
+
1: "22pt",
|
|
3201
|
+
2: "18pt",
|
|
3202
|
+
3: "16pt",
|
|
3203
|
+
4: "14pt",
|
|
3204
|
+
5: "12pt",
|
|
3205
|
+
6: "12pt"
|
|
3206
|
+
}),
|
|
3207
|
+
browser: Object.freeze({
|
|
3208
|
+
1: "24pt",
|
|
3209
|
+
2: "18pt",
|
|
3210
|
+
3: "14pt",
|
|
3211
|
+
4: "12pt",
|
|
3212
|
+
5: "10pt",
|
|
3213
|
+
6: "8pt"
|
|
3214
|
+
}),
|
|
3215
|
+
githubEm: Object.freeze({
|
|
3216
|
+
1: "32pt",
|
|
3217
|
+
2: "24pt",
|
|
3218
|
+
3: "20pt",
|
|
3219
|
+
4: "16pt",
|
|
3220
|
+
5: "14pt",
|
|
3221
|
+
6: "14pt"
|
|
3222
|
+
})
|
|
3223
|
+
});
|
|
3224
|
+
var HEADING_TAGS = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
3225
|
+
function isHeaderSizePresetName(value) {
|
|
3226
|
+
return Object.prototype.hasOwnProperty.call(HEADER_SIZE_PRESETS, value);
|
|
3227
|
+
}
|
|
3228
|
+
function resolveHeadingPolicy(metadata) {
|
|
3229
|
+
if (!metadata) return void 0;
|
|
3230
|
+
const align = metadata.headingAlign === "left" || metadata.headingAlign === "center" || metadata.headingAlign === "right" ? metadata.headingAlign : void 0;
|
|
3231
|
+
const bold = metadata.headingBold === true;
|
|
3232
|
+
const auto = metadata.headingAuto === true;
|
|
3233
|
+
const presetRaw = metadata.headingSizeGridPreset;
|
|
3234
|
+
const sizePreset = !auto && typeof presetRaw === "string" && isHeaderSizePresetName(presetRaw) ? presetRaw : void 0;
|
|
3235
|
+
if (align === void 0 && !bold && sizePreset === void 0 && !auto) {
|
|
3236
|
+
return void 0;
|
|
3237
|
+
}
|
|
3238
|
+
return { align, bold, sizePreset, auto };
|
|
3239
|
+
}
|
|
3240
|
+
function headingLevelFromTag(tag) {
|
|
3241
|
+
if (!HEADING_TAGS.has(tag)) return void 0;
|
|
3242
|
+
const n = Number(tag.slice(1));
|
|
3243
|
+
if (n >= 1 && n <= 6) return n;
|
|
3244
|
+
return void 0;
|
|
3245
|
+
}
|
|
3246
|
+
function headingPolicyStyleParts(tag, blockAttributes, policy) {
|
|
3247
|
+
if (!policy) return [];
|
|
3248
|
+
const level = headingLevelFromTag(tag);
|
|
3249
|
+
if (level === void 0) return [];
|
|
3250
|
+
const parts = [];
|
|
3251
|
+
const bakedAlign = blockAttributes?.align;
|
|
3252
|
+
if (policy.align && policy.align !== "left" && !(typeof bakedAlign === "string" && bakedAlign.length > 0)) {
|
|
3253
|
+
parts.push(`text-align: ${policy.align}`);
|
|
3254
|
+
}
|
|
3255
|
+
if (policy.bold) {
|
|
3256
|
+
parts.push("font-weight: bold");
|
|
3257
|
+
}
|
|
3258
|
+
if (policy.sizePreset) {
|
|
3259
|
+
const size = HEADER_SIZE_PRESETS[policy.sizePreset][level];
|
|
3260
|
+
if (size) parts.push(`font-size: ${size}`);
|
|
3261
|
+
}
|
|
3262
|
+
return parts;
|
|
3263
|
+
}
|
|
3264
|
+
|
|
3177
3265
|
// src/conversion/html/table-presentation.ts
|
|
3178
3266
|
var DEFAULT_BORDER_COLOR = "#e7e7e7";
|
|
3179
3267
|
var DEFAULT_HEADER_BG = "#f5f5f5";
|
|
@@ -3338,6 +3426,12 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3338
3426
|
const resolvedDocumentPresentation = resolveDocumentPresentation(
|
|
3339
3427
|
options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
|
|
3340
3428
|
);
|
|
3429
|
+
const resolvedHeadingPolicy = resolveHeadingPolicy(options.documentMetadata);
|
|
3430
|
+
const effectiveTablePresentation = options.tablePresentation ?? options.documentMetadata?.tablePresentation;
|
|
3431
|
+
const optionsWithTable = {
|
|
3432
|
+
...options,
|
|
3433
|
+
...effectiveTablePresentation !== void 0 ? { tablePresentation: effectiveTablePresentation } : {}
|
|
3434
|
+
};
|
|
3341
3435
|
let html = "";
|
|
3342
3436
|
let listStack = [];
|
|
3343
3437
|
let counters = [];
|
|
@@ -3350,7 +3444,7 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3350
3444
|
listStack = [];
|
|
3351
3445
|
counters = [];
|
|
3352
3446
|
const tableLines = collectAdjacentTableLines(lines, i);
|
|
3353
|
-
html += renderTable(tableLines, embedRenderers, pretty, blockHandlers,
|
|
3447
|
+
html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, optionsWithTable);
|
|
3354
3448
|
i += tableLines.length - 1;
|
|
3355
3449
|
continue;
|
|
3356
3450
|
}
|
|
@@ -3441,7 +3535,8 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3441
3535
|
line.attributes,
|
|
3442
3536
|
pretty,
|
|
3443
3537
|
headingId,
|
|
3444
|
-
resolvedDocumentPresentation
|
|
3538
|
+
resolvedDocumentPresentation,
|
|
3539
|
+
resolvedHeadingPolicy
|
|
3445
3540
|
);
|
|
3446
3541
|
}
|
|
3447
3542
|
}
|
|
@@ -3761,19 +3856,23 @@ function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hi
|
|
|
3761
3856
|
const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
|
|
3762
3857
|
return pretty ? html + "\n" : html;
|
|
3763
3858
|
}
|
|
3764
|
-
function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation) {
|
|
3859
|
+
function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation, resolvedHeadingPolicy) {
|
|
3765
3860
|
const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
|
|
3766
|
-
const styleAttr = getBlockStyleAttribute(
|
|
3861
|
+
const styleAttr = getBlockStyleAttribute(
|
|
3862
|
+
tag,
|
|
3863
|
+
attributes,
|
|
3864
|
+
resolvedDocumentPresentation,
|
|
3865
|
+
resolvedHeadingPolicy
|
|
3866
|
+
);
|
|
3767
3867
|
const innerContent = content || "<br>";
|
|
3768
3868
|
const html = `<${tag}${idAttr}${styleAttr}>${innerContent}</${tag}>`;
|
|
3769
3869
|
return pretty ? html + "\n" : html;
|
|
3770
3870
|
}
|
|
3771
|
-
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
|
|
3772
|
-
const styles =
|
|
3773
|
-
tag,
|
|
3774
|
-
attributes,
|
|
3775
|
-
|
|
3776
|
-
);
|
|
3871
|
+
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation, resolvedHeadingPolicy) {
|
|
3872
|
+
const styles = [
|
|
3873
|
+
...blockPresentationStyleParts(tag, attributes, resolvedDocumentPresentation),
|
|
3874
|
+
...headingPolicyStyleParts(tag, attributes, resolvedHeadingPolicy)
|
|
3875
|
+
];
|
|
3777
3876
|
if (attributes) {
|
|
3778
3877
|
const alignVal = attributes.align;
|
|
3779
3878
|
if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
|
|
@@ -6093,6 +6192,7 @@ export {
|
|
|
6093
6192
|
BOX_OVERFLOW_VALUES,
|
|
6094
6193
|
BlockHandlerRegistry,
|
|
6095
6194
|
BrowserDOMAdapter,
|
|
6195
|
+
HEADER_SIZE_PRESETS,
|
|
6096
6196
|
LINE_HEIGHT_BLOCK_TAGS,
|
|
6097
6197
|
NODE_TYPE,
|
|
6098
6198
|
NodeDOMAdapter,
|
|
@@ -6147,6 +6247,7 @@ export {
|
|
|
6147
6247
|
getNamedColors,
|
|
6148
6248
|
headerFormat,
|
|
6149
6249
|
headerIdFormat,
|
|
6250
|
+
headingPolicyStyleParts,
|
|
6150
6251
|
htmlToDelta,
|
|
6151
6252
|
imageFormat,
|
|
6152
6253
|
indentFormat,
|
|
@@ -6175,6 +6276,7 @@ export {
|
|
|
6175
6276
|
preloadRemark,
|
|
6176
6277
|
renderDelta,
|
|
6177
6278
|
resolveDocumentPresentation,
|
|
6279
|
+
resolveHeadingPolicy,
|
|
6178
6280
|
resolveTablePresentation,
|
|
6179
6281
|
sanitizeDelta,
|
|
6180
6282
|
sizeFormat,
|