@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.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
BOX_OVERFLOW_VALUES: () => BOX_OVERFLOW_VALUES,
|
|
37
37
|
BlockHandlerRegistry: () => BlockHandlerRegistry,
|
|
38
38
|
BrowserDOMAdapter: () => BrowserDOMAdapter,
|
|
39
|
+
HEADER_SIZE_PRESETS: () => HEADER_SIZE_PRESETS,
|
|
39
40
|
LINE_HEIGHT_BLOCK_TAGS: () => LINE_HEIGHT_BLOCK_TAGS,
|
|
40
41
|
NODE_TYPE: () => NODE_TYPE,
|
|
41
42
|
NodeDOMAdapter: () => NodeDOMAdapter,
|
|
@@ -90,6 +91,7 @@ __export(index_exports, {
|
|
|
90
91
|
getNamedColors: () => getNamedColors,
|
|
91
92
|
headerFormat: () => headerFormat,
|
|
92
93
|
headerIdFormat: () => headerIdFormat,
|
|
94
|
+
headingPolicyStyleParts: () => headingPolicyStyleParts,
|
|
93
95
|
htmlToDelta: () => htmlToDelta,
|
|
94
96
|
imageFormat: () => imageFormat,
|
|
95
97
|
indentFormat: () => indentFormat,
|
|
@@ -118,6 +120,7 @@ __export(index_exports, {
|
|
|
118
120
|
preloadRemark: () => preloadRemark,
|
|
119
121
|
renderDelta: () => renderDelta,
|
|
120
122
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
123
|
+
resolveHeadingPolicy: () => resolveHeadingPolicy,
|
|
121
124
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
122
125
|
sanitizeDelta: () => sanitizeDelta,
|
|
123
126
|
sizeFormat: () => sizeFormat,
|
|
@@ -595,9 +598,13 @@ var EMBED_RENDERERS = {
|
|
|
595
598
|
const embedSrc = toCodeWidgetEmbedUrl(src);
|
|
596
599
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
597
600
|
},
|
|
601
|
+
// `data-scrider-embed` marks this span as 1 Delta char for DomBridge before
|
|
602
|
+
// KaTeX post-render replaces the text body with a `.katex` subtree. Without
|
|
603
|
+
// the marker, DomBridge counts the raw LaTeX length and drifts indices for
|
|
604
|
+
// everything after the formula (e.g. Simple Table chrome probe fails).
|
|
598
605
|
formula: (value) => {
|
|
599
606
|
const latex = typeof value === "string" ? value : "";
|
|
600
|
-
return `<span class="formula" data-formula="${escapeHtml(latex)}">${escapeHtml(latex)}</span>`;
|
|
607
|
+
return `<span class="formula" data-formula="${escapeHtml(latex)}" data-scrider-embed>${escapeHtml(latex)}</span>`;
|
|
601
608
|
},
|
|
602
609
|
diagram: (value) => {
|
|
603
610
|
const source = typeof value === "string" ? value : "";
|
|
@@ -2723,7 +2730,7 @@ var formulaFormat = {
|
|
|
2723
2730
|
},
|
|
2724
2731
|
render(value) {
|
|
2725
2732
|
const latex = typeof value === "string" ? value : "";
|
|
2726
|
-
return `<span class="formula" data-formula="${escapeHtml(latex)}">${escapeHtml(latex)}</span>`;
|
|
2733
|
+
return `<span class="formula" data-formula="${escapeHtml(latex)}" data-scrider-embed>${escapeHtml(latex)}</span>`;
|
|
2727
2734
|
},
|
|
2728
2735
|
match(element) {
|
|
2729
2736
|
if (element.tagName.toLowerCase() !== "span") return null;
|
|
@@ -3310,6 +3317,90 @@ function joinStyleParts(parts) {
|
|
|
3310
3317
|
return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
|
|
3311
3318
|
}
|
|
3312
3319
|
|
|
3320
|
+
// src/conversion/html/heading-presentation.ts
|
|
3321
|
+
var HEADER_SIZE_PRESETS = Object.freeze({
|
|
3322
|
+
scrider: Object.freeze({
|
|
3323
|
+
1: "32pt",
|
|
3324
|
+
2: "24pt",
|
|
3325
|
+
3: "20pt",
|
|
3326
|
+
4: "18pt",
|
|
3327
|
+
5: "16pt",
|
|
3328
|
+
6: "14pt"
|
|
3329
|
+
}),
|
|
3330
|
+
google: Object.freeze({
|
|
3331
|
+
1: "26pt",
|
|
3332
|
+
2: "20pt",
|
|
3333
|
+
3: "16pt",
|
|
3334
|
+
4: "14pt",
|
|
3335
|
+
5: "12pt",
|
|
3336
|
+
6: "11pt"
|
|
3337
|
+
}),
|
|
3338
|
+
word: Object.freeze({
|
|
3339
|
+
1: "22pt",
|
|
3340
|
+
2: "18pt",
|
|
3341
|
+
3: "16pt",
|
|
3342
|
+
4: "14pt",
|
|
3343
|
+
5: "12pt",
|
|
3344
|
+
6: "12pt"
|
|
3345
|
+
}),
|
|
3346
|
+
browser: Object.freeze({
|
|
3347
|
+
1: "24pt",
|
|
3348
|
+
2: "18pt",
|
|
3349
|
+
3: "14pt",
|
|
3350
|
+
4: "12pt",
|
|
3351
|
+
5: "10pt",
|
|
3352
|
+
6: "8pt"
|
|
3353
|
+
}),
|
|
3354
|
+
githubEm: Object.freeze({
|
|
3355
|
+
1: "32pt",
|
|
3356
|
+
2: "24pt",
|
|
3357
|
+
3: "20pt",
|
|
3358
|
+
4: "16pt",
|
|
3359
|
+
5: "14pt",
|
|
3360
|
+
6: "14pt"
|
|
3361
|
+
})
|
|
3362
|
+
});
|
|
3363
|
+
var HEADING_TAGS = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
3364
|
+
function isHeaderSizePresetName(value) {
|
|
3365
|
+
return Object.prototype.hasOwnProperty.call(HEADER_SIZE_PRESETS, value);
|
|
3366
|
+
}
|
|
3367
|
+
function resolveHeadingPolicy(metadata) {
|
|
3368
|
+
if (!metadata) return void 0;
|
|
3369
|
+
const align = metadata.headingAlign === "left" || metadata.headingAlign === "center" || metadata.headingAlign === "right" ? metadata.headingAlign : void 0;
|
|
3370
|
+
const bold = metadata.headingBold === true;
|
|
3371
|
+
const auto = metadata.headingAuto === true;
|
|
3372
|
+
const presetRaw = metadata.headingSizeGridPreset;
|
|
3373
|
+
const sizePreset = !auto && typeof presetRaw === "string" && isHeaderSizePresetName(presetRaw) ? presetRaw : void 0;
|
|
3374
|
+
if (align === void 0 && !bold && sizePreset === void 0 && !auto) {
|
|
3375
|
+
return void 0;
|
|
3376
|
+
}
|
|
3377
|
+
return { align, bold, sizePreset, auto };
|
|
3378
|
+
}
|
|
3379
|
+
function headingLevelFromTag(tag) {
|
|
3380
|
+
if (!HEADING_TAGS.has(tag)) return void 0;
|
|
3381
|
+
const n = Number(tag.slice(1));
|
|
3382
|
+
if (n >= 1 && n <= 6) return n;
|
|
3383
|
+
return void 0;
|
|
3384
|
+
}
|
|
3385
|
+
function headingPolicyStyleParts(tag, blockAttributes, policy) {
|
|
3386
|
+
if (!policy) return [];
|
|
3387
|
+
const level = headingLevelFromTag(tag);
|
|
3388
|
+
if (level === void 0) return [];
|
|
3389
|
+
const parts = [];
|
|
3390
|
+
const bakedAlign = blockAttributes?.align;
|
|
3391
|
+
if (policy.align && policy.align !== "left" && !(typeof bakedAlign === "string" && bakedAlign.length > 0)) {
|
|
3392
|
+
parts.push(`text-align: ${policy.align}`);
|
|
3393
|
+
}
|
|
3394
|
+
if (policy.bold) {
|
|
3395
|
+
parts.push("font-weight: bold");
|
|
3396
|
+
}
|
|
3397
|
+
if (policy.sizePreset) {
|
|
3398
|
+
const size = HEADER_SIZE_PRESETS[policy.sizePreset][level];
|
|
3399
|
+
if (size) parts.push(`font-size: ${size}`);
|
|
3400
|
+
}
|
|
3401
|
+
return parts;
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3313
3404
|
// src/conversion/html/table-presentation.ts
|
|
3314
3405
|
var DEFAULT_BORDER_COLOR = "#e7e7e7";
|
|
3315
3406
|
var DEFAULT_HEADER_BG = "#f5f5f5";
|
|
@@ -3474,6 +3565,12 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3474
3565
|
const resolvedDocumentPresentation = resolveDocumentPresentation(
|
|
3475
3566
|
options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
|
|
3476
3567
|
);
|
|
3568
|
+
const resolvedHeadingPolicy = resolveHeadingPolicy(options.documentMetadata);
|
|
3569
|
+
const effectiveTablePresentation = options.tablePresentation ?? options.documentMetadata?.tablePresentation;
|
|
3570
|
+
const optionsWithTable = {
|
|
3571
|
+
...options,
|
|
3572
|
+
...effectiveTablePresentation !== void 0 ? { tablePresentation: effectiveTablePresentation } : {}
|
|
3573
|
+
};
|
|
3477
3574
|
let html = "";
|
|
3478
3575
|
let listStack = [];
|
|
3479
3576
|
let counters = [];
|
|
@@ -3486,7 +3583,7 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3486
3583
|
listStack = [];
|
|
3487
3584
|
counters = [];
|
|
3488
3585
|
const tableLines = collectAdjacentTableLines(lines, i);
|
|
3489
|
-
html += renderTable(tableLines, embedRenderers, pretty, blockHandlers,
|
|
3586
|
+
html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, optionsWithTable);
|
|
3490
3587
|
i += tableLines.length - 1;
|
|
3491
3588
|
continue;
|
|
3492
3589
|
}
|
|
@@ -3577,7 +3674,8 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3577
3674
|
line.attributes,
|
|
3578
3675
|
pretty,
|
|
3579
3676
|
headingId,
|
|
3580
|
-
resolvedDocumentPresentation
|
|
3677
|
+
resolvedDocumentPresentation,
|
|
3678
|
+
resolvedHeadingPolicy
|
|
3581
3679
|
);
|
|
3582
3680
|
}
|
|
3583
3681
|
}
|
|
@@ -3897,19 +3995,23 @@ function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hi
|
|
|
3897
3995
|
const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
|
|
3898
3996
|
return pretty ? html + "\n" : html;
|
|
3899
3997
|
}
|
|
3900
|
-
function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation) {
|
|
3998
|
+
function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation, resolvedHeadingPolicy) {
|
|
3901
3999
|
const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
|
|
3902
|
-
const styleAttr = getBlockStyleAttribute(
|
|
4000
|
+
const styleAttr = getBlockStyleAttribute(
|
|
4001
|
+
tag,
|
|
4002
|
+
attributes,
|
|
4003
|
+
resolvedDocumentPresentation,
|
|
4004
|
+
resolvedHeadingPolicy
|
|
4005
|
+
);
|
|
3903
4006
|
const innerContent = content || "<br>";
|
|
3904
4007
|
const html = `<${tag}${idAttr}${styleAttr}>${innerContent}</${tag}>`;
|
|
3905
4008
|
return pretty ? html + "\n" : html;
|
|
3906
4009
|
}
|
|
3907
|
-
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
|
|
3908
|
-
const styles =
|
|
3909
|
-
tag,
|
|
3910
|
-
attributes,
|
|
3911
|
-
|
|
3912
|
-
);
|
|
4010
|
+
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation, resolvedHeadingPolicy) {
|
|
4011
|
+
const styles = [
|
|
4012
|
+
...blockPresentationStyleParts(tag, attributes, resolvedDocumentPresentation),
|
|
4013
|
+
...headingPolicyStyleParts(tag, attributes, resolvedHeadingPolicy)
|
|
4014
|
+
];
|
|
3913
4015
|
if (attributes) {
|
|
3914
4016
|
const alignVal = attributes.align;
|
|
3915
4017
|
if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
|
|
@@ -6230,6 +6332,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6230
6332
|
BOX_OVERFLOW_VALUES,
|
|
6231
6333
|
BlockHandlerRegistry,
|
|
6232
6334
|
BrowserDOMAdapter,
|
|
6335
|
+
HEADER_SIZE_PRESETS,
|
|
6233
6336
|
LINE_HEIGHT_BLOCK_TAGS,
|
|
6234
6337
|
NODE_TYPE,
|
|
6235
6338
|
NodeDOMAdapter,
|
|
@@ -6284,6 +6387,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6284
6387
|
getNamedColors,
|
|
6285
6388
|
headerFormat,
|
|
6286
6389
|
headerIdFormat,
|
|
6390
|
+
headingPolicyStyleParts,
|
|
6287
6391
|
htmlToDelta,
|
|
6288
6392
|
imageFormat,
|
|
6289
6393
|
indentFormat,
|
|
@@ -6312,6 +6416,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6312
6416
|
preloadRemark,
|
|
6313
6417
|
renderDelta,
|
|
6314
6418
|
resolveDocumentPresentation,
|
|
6419
|
+
resolveHeadingPolicy,
|
|
6315
6420
|
resolveTablePresentation,
|
|
6316
6421
|
sanitizeDelta,
|
|
6317
6422
|
sizeFormat,
|