@scrider/formatter 1.10.3 → 1.10.5
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 +43 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -23
- package/dist/index.d.ts +42 -23
- package/dist/index.js +39 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,9 @@ __export(index_exports, {
|
|
|
46
46
|
SCRIDER_MARGIN_AFTER_KEY: () => SCRIDER_MARGIN_AFTER_KEY,
|
|
47
47
|
SCRIDER_MARGIN_BEFORE_KEY: () => SCRIDER_MARGIN_BEFORE_KEY,
|
|
48
48
|
SCRIDER_TEXT_INDENT_KEY: () => SCRIDER_TEXT_INDENT_KEY,
|
|
49
|
+
TABLE_BORDER_COLOR: () => TABLE_BORDER_COLOR,
|
|
50
|
+
TABLE_HEADER_BG: () => TABLE_HEADER_BG,
|
|
51
|
+
TABLE_ZEBRA_BG: () => TABLE_ZEBRA_BG,
|
|
49
52
|
TEXT_INDENT_BLOCK_TAGS: () => TEXT_INDENT_BLOCK_TAGS,
|
|
50
53
|
alertBlockHandler: () => alertBlockHandler,
|
|
51
54
|
alignFormat: () => alignFormat,
|
|
@@ -119,6 +122,7 @@ __export(index_exports, {
|
|
|
119
122
|
parseScriderMarginEm: () => parseScriderMarginEm,
|
|
120
123
|
preloadRemark: () => preloadRemark,
|
|
121
124
|
renderDelta: () => renderDelta,
|
|
125
|
+
resolveCodeWidgetEmbedSrc: () => resolveCodeWidgetEmbedSrc,
|
|
122
126
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
123
127
|
resolveHeadingPolicy: () => resolveHeadingPolicy,
|
|
124
128
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
@@ -595,7 +599,7 @@ var EMBED_RENDERERS = {
|
|
|
595
599
|
if (h && h !== "auto") styles.push(`height: ${/^\d+$/.test(h) ? h + "px" : h}`);
|
|
596
600
|
}
|
|
597
601
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
598
|
-
const embedSrc =
|
|
602
|
+
const embedSrc = resolveCodeWidgetEmbedSrc(src, context);
|
|
599
603
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
600
604
|
},
|
|
601
605
|
// `data-scrider-embed` marks this span as 1 Delta char for DomBridge before
|
|
@@ -695,31 +699,6 @@ function fromVideoEmbedUrl(embedUrl) {
|
|
|
695
699
|
}
|
|
696
700
|
return embedUrl;
|
|
697
701
|
}
|
|
698
|
-
function splitUrl(url) {
|
|
699
|
-
let rest = url;
|
|
700
|
-
let hash = "";
|
|
701
|
-
const hashIdx = rest.indexOf("#");
|
|
702
|
-
if (hashIdx >= 0) {
|
|
703
|
-
hash = rest.slice(hashIdx);
|
|
704
|
-
rest = rest.slice(0, hashIdx);
|
|
705
|
-
}
|
|
706
|
-
let query = "";
|
|
707
|
-
const qIdx = rest.indexOf("?");
|
|
708
|
-
if (qIdx >= 0) {
|
|
709
|
-
query = rest.slice(qIdx);
|
|
710
|
-
rest = rest.slice(0, qIdx);
|
|
711
|
-
}
|
|
712
|
-
return { base: rest, query, hash };
|
|
713
|
-
}
|
|
714
|
-
function hasQueryParam(url, key) {
|
|
715
|
-
const { query } = splitUrl(url);
|
|
716
|
-
return new RegExp(`[?&]${key}=`, "i").test(query);
|
|
717
|
-
}
|
|
718
|
-
function appendQueryParam(url, key, value) {
|
|
719
|
-
const { base, query, hash } = splitUrl(url);
|
|
720
|
-
const next = query ? `${query}&${key}=${value}` : `?${key}=${value}`;
|
|
721
|
-
return `${base}${next}${hash}`;
|
|
722
|
-
}
|
|
723
702
|
var CODE_WIDGET_IFRAME_ALLOW = "accelerometer; camera; encrypted-media; geolocation; gyroscope; microphone; midi; payment; usb; xr-spatial-tracking; cross-origin-isolated";
|
|
724
703
|
function renderEmbedIframeIsolationAttrs(context, kind) {
|
|
725
704
|
const opts = context?.embed;
|
|
@@ -732,38 +711,13 @@ function renderEmbedIframeIsolationAttrs(context, kind) {
|
|
|
732
711
|
}
|
|
733
712
|
return parts.length ? ` ${parts.join(" ")}` : "";
|
|
734
713
|
}
|
|
735
|
-
function
|
|
714
|
+
function resolveCodeWidgetEmbedSrc(url, context) {
|
|
736
715
|
const u = typeof url === "string" ? url.trim() : "";
|
|
737
716
|
if (!u) return "";
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
if (/codesandbox\.io\/embed\//i.test(u)) return u;
|
|
743
|
-
return u.replace(/codesandbox\.io\/s\//i, "codesandbox.io/embed/");
|
|
744
|
-
}
|
|
745
|
-
if (/(?:\/\/|^)(?:[\w-]+\.)*replit\.com\//i.test(u)) {
|
|
746
|
-
return hasQueryParam(u, "embed") ? u : appendQueryParam(u, "embed", "true");
|
|
747
|
-
}
|
|
748
|
-
if (/(?:\/\/|^)(?:[\w-]+\.)*codepen\.io\//i.test(u)) {
|
|
749
|
-
if (/codepen\.io\/[^/]+\/embed\//i.test(u)) return u;
|
|
750
|
-
return u.replace(/(codepen\.io\/[^/]+)\/pen\//i, "$1/embed/");
|
|
751
|
-
}
|
|
752
|
-
if (/(?:\/\/|^)(?:[\w-]+\.)*jsfiddle\.net\//i.test(u)) {
|
|
753
|
-
const { base, query, hash } = splitUrl(u);
|
|
754
|
-
if (/\/embedded(?:\/|$)/i.test(base)) return u;
|
|
755
|
-
const trimmed = base.replace(/\/+$/, "");
|
|
756
|
-
return `${trimmed}/embedded/${query}${hash}`;
|
|
757
|
-
}
|
|
758
|
-
if (/(?:\/\/|^)(?:[\w-]+\.)*trinket\.io\//i.test(u)) {
|
|
759
|
-
if (/trinket\.io\/embed\//i.test(u)) return u;
|
|
760
|
-
return u.replace(/trinket\.io\//i, "trinket.io/embed/");
|
|
761
|
-
}
|
|
762
|
-
if (/(?:\/\/|^)(?:[\w-]+\.)*onecompiler\.com\//i.test(u)) {
|
|
763
|
-
if (/onecompiler\.com\/embed\//i.test(u)) return u;
|
|
764
|
-
return u.replace(/onecompiler\.com\//i, "onecompiler.com/embed/");
|
|
765
|
-
}
|
|
766
|
-
return u;
|
|
717
|
+
return context?.codeWidgetEmbedUrl ? context.codeWidgetEmbedUrl(u) : u;
|
|
718
|
+
}
|
|
719
|
+
function toCodeWidgetEmbedUrl(url) {
|
|
720
|
+
return typeof url === "string" ? url.trim() : "";
|
|
767
721
|
}
|
|
768
722
|
|
|
769
723
|
// src/schema/blocks/table.ts
|
|
@@ -2606,7 +2560,7 @@ var codeWidgetFormat = {
|
|
|
2606
2560
|
if (h && h !== "auto") styles.push(`height: ${/^\d+$/.test(h) ? h + "px" : h}`);
|
|
2607
2561
|
}
|
|
2608
2562
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
2609
|
-
const embedSrc =
|
|
2563
|
+
const embedSrc = resolveCodeWidgetEmbedSrc(src, context);
|
|
2610
2564
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
2611
2565
|
},
|
|
2612
2566
|
match(element) {
|
|
@@ -3402,9 +3356,12 @@ function headingPolicyStyleParts(tag, blockAttributes, policy) {
|
|
|
3402
3356
|
}
|
|
3403
3357
|
|
|
3404
3358
|
// src/conversion/html/table-presentation.ts
|
|
3405
|
-
var
|
|
3406
|
-
var
|
|
3407
|
-
var
|
|
3359
|
+
var TABLE_BORDER_COLOR = "#e7e7e7";
|
|
3360
|
+
var TABLE_HEADER_BG = "#f5f5f5";
|
|
3361
|
+
var TABLE_ZEBRA_BG = "#f6f8fa";
|
|
3362
|
+
var DEFAULT_BORDER_COLOR = TABLE_BORDER_COLOR;
|
|
3363
|
+
var DEFAULT_HEADER_BG = TABLE_HEADER_BG;
|
|
3364
|
+
var DEFAULT_ZEBRA_BG = TABLE_ZEBRA_BG;
|
|
3408
3365
|
var CELL_PADDING = "6px 13px";
|
|
3409
3366
|
function resolveTablePresentation(presentation) {
|
|
3410
3367
|
return {
|
|
@@ -4103,7 +4060,10 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
|
|
|
4103
4060
|
return "";
|
|
4104
4061
|
}
|
|
4105
4062
|
const embedValue = value[embedType];
|
|
4106
|
-
const embedContext =
|
|
4063
|
+
const embedContext = {
|
|
4064
|
+
...options?.embed != null ? { embed: options.embed } : {},
|
|
4065
|
+
...options?.codeWidgetEmbedUrl != null ? { codeWidgetEmbedUrl: options.codeWidgetEmbedUrl } : {}
|
|
4066
|
+
};
|
|
4107
4067
|
const registry = options?.registry;
|
|
4108
4068
|
if (registry) {
|
|
4109
4069
|
const format = registry.get(embedType);
|
|
@@ -4937,7 +4897,8 @@ function deltaToMarkdown(delta, options = {}) {
|
|
|
4937
4897
|
prettyHtml = false,
|
|
4938
4898
|
registry,
|
|
4939
4899
|
softBreakStyle = "spaces",
|
|
4940
|
-
trimTrailingNewlines = false
|
|
4900
|
+
trimTrailingNewlines = false,
|
|
4901
|
+
codeWidgetEmbedUrl
|
|
4941
4902
|
} = options;
|
|
4942
4903
|
const useLatexDelimiters = mathSyntax === "latex";
|
|
4943
4904
|
const lines = splitIntoLines2(delta.ops);
|
|
@@ -4979,7 +4940,9 @@ function deltaToMarkdown(delta, options = {}) {
|
|
|
4979
4940
|
blockHandlers,
|
|
4980
4941
|
false,
|
|
4981
4942
|
registry,
|
|
4982
|
-
softBreakStyle
|
|
4943
|
+
softBreakStyle,
|
|
4944
|
+
false,
|
|
4945
|
+
codeWidgetEmbedUrl
|
|
4983
4946
|
)
|
|
4984
4947
|
).join("\n");
|
|
4985
4948
|
if (language === "math") {
|
|
@@ -5031,7 +4994,9 @@ ${code}
|
|
|
5031
4994
|
blockHandlers,
|
|
5032
4995
|
prettyHtml,
|
|
5033
4996
|
registry,
|
|
5034
|
-
softBreakStyle
|
|
4997
|
+
softBreakStyle,
|
|
4998
|
+
false,
|
|
4999
|
+
codeWidgetEmbedUrl
|
|
5035
5000
|
);
|
|
5036
5001
|
if (!content && !hasBlockFormat(attrs)) {
|
|
5037
5002
|
result.push(preserveEmptyLines ? "<br>" : "");
|
|
@@ -5255,7 +5220,7 @@ function getCodeBlockId2(attributes) {
|
|
|
5255
5220
|
const id = attributes["code-block-id"];
|
|
5256
5221
|
return typeof id === "string" ? id : void 0;
|
|
5257
5222
|
}
|
|
5258
|
-
function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false) {
|
|
5223
|
+
function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false, codeWidgetEmbedUrl) {
|
|
5259
5224
|
let result = "";
|
|
5260
5225
|
for (const op of ops) {
|
|
5261
5226
|
const attrs = op.attributes;
|
|
@@ -5277,7 +5242,8 @@ function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters
|
|
|
5277
5242
|
prettyHtml,
|
|
5278
5243
|
registry,
|
|
5279
5244
|
softBreakStyle,
|
|
5280
|
-
inTableCell
|
|
5245
|
+
inTableCell,
|
|
5246
|
+
codeWidgetEmbedUrl
|
|
5281
5247
|
);
|
|
5282
5248
|
}
|
|
5283
5249
|
}
|
|
@@ -5311,7 +5277,7 @@ function renderInlineText2(text, attributes) {
|
|
|
5311
5277
|
}
|
|
5312
5278
|
return result;
|
|
5313
5279
|
}
|
|
5314
|
-
function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false) {
|
|
5280
|
+
function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false, codeWidgetEmbedUrl) {
|
|
5315
5281
|
const entries = Object.entries(embed);
|
|
5316
5282
|
if (entries.length === 0) return "";
|
|
5317
5283
|
const firstEntry = entries[0];
|
|
@@ -5360,7 +5326,11 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
|
|
|
5360
5326
|
if (md !== null) return md;
|
|
5361
5327
|
}
|
|
5362
5328
|
if (format.render) {
|
|
5363
|
-
return format.render(
|
|
5329
|
+
return format.render(
|
|
5330
|
+
embedValue,
|
|
5331
|
+
attributes,
|
|
5332
|
+
codeWidgetEmbedUrl != null ? { codeWidgetEmbedUrl } : void 0
|
|
5333
|
+
);
|
|
5364
5334
|
}
|
|
5365
5335
|
}
|
|
5366
5336
|
}
|
|
@@ -5421,7 +5391,7 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
|
|
|
5421
5391
|
if (h && h !== "auto") styles.push(`height: ${/^\d+$/.test(h) ? h + "px" : h}`);
|
|
5422
5392
|
}
|
|
5423
5393
|
const styleAttr = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
5424
|
-
const embedSrc =
|
|
5394
|
+
const embedSrc = codeWidgetEmbedUrl ? codeWidgetEmbedUrl(src) : src;
|
|
5425
5395
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${floatAttr}${styleAttr}></iframe>`;
|
|
5426
5396
|
}
|
|
5427
5397
|
return ``;
|
|
@@ -6342,6 +6312,9 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6342
6312
|
SCRIDER_MARGIN_AFTER_KEY,
|
|
6343
6313
|
SCRIDER_MARGIN_BEFORE_KEY,
|
|
6344
6314
|
SCRIDER_TEXT_INDENT_KEY,
|
|
6315
|
+
TABLE_BORDER_COLOR,
|
|
6316
|
+
TABLE_HEADER_BG,
|
|
6317
|
+
TABLE_ZEBRA_BG,
|
|
6345
6318
|
TEXT_INDENT_BLOCK_TAGS,
|
|
6346
6319
|
alertBlockHandler,
|
|
6347
6320
|
alignFormat,
|
|
@@ -6415,6 +6388,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6415
6388
|
parseScriderMarginEm,
|
|
6416
6389
|
preloadRemark,
|
|
6417
6390
|
renderDelta,
|
|
6391
|
+
resolveCodeWidgetEmbedSrc,
|
|
6418
6392
|
resolveDocumentPresentation,
|
|
6419
6393
|
resolveHeadingPolicy,
|
|
6420
6394
|
resolveTablePresentation,
|