@scrider/formatter 1.10.3 → 1.10.4
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 +31 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -23
- package/dist/index.d.ts +33 -23
- package/dist/index.js +30 -66
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -119,6 +119,7 @@ __export(index_exports, {
|
|
|
119
119
|
parseScriderMarginEm: () => parseScriderMarginEm,
|
|
120
120
|
preloadRemark: () => preloadRemark,
|
|
121
121
|
renderDelta: () => renderDelta,
|
|
122
|
+
resolveCodeWidgetEmbedSrc: () => resolveCodeWidgetEmbedSrc,
|
|
122
123
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
123
124
|
resolveHeadingPolicy: () => resolveHeadingPolicy,
|
|
124
125
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
@@ -595,7 +596,7 @@ var EMBED_RENDERERS = {
|
|
|
595
596
|
if (h && h !== "auto") styles.push(`height: ${/^\d+$/.test(h) ? h + "px" : h}`);
|
|
596
597
|
}
|
|
597
598
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
598
|
-
const embedSrc =
|
|
599
|
+
const embedSrc = resolveCodeWidgetEmbedSrc(src, context);
|
|
599
600
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
600
601
|
},
|
|
601
602
|
// `data-scrider-embed` marks this span as 1 Delta char for DomBridge before
|
|
@@ -695,31 +696,6 @@ function fromVideoEmbedUrl(embedUrl) {
|
|
|
695
696
|
}
|
|
696
697
|
return embedUrl;
|
|
697
698
|
}
|
|
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
699
|
var CODE_WIDGET_IFRAME_ALLOW = "accelerometer; camera; encrypted-media; geolocation; gyroscope; microphone; midi; payment; usb; xr-spatial-tracking; cross-origin-isolated";
|
|
724
700
|
function renderEmbedIframeIsolationAttrs(context, kind) {
|
|
725
701
|
const opts = context?.embed;
|
|
@@ -732,38 +708,13 @@ function renderEmbedIframeIsolationAttrs(context, kind) {
|
|
|
732
708
|
}
|
|
733
709
|
return parts.length ? ` ${parts.join(" ")}` : "";
|
|
734
710
|
}
|
|
735
|
-
function
|
|
711
|
+
function resolveCodeWidgetEmbedSrc(url, context) {
|
|
736
712
|
const u = typeof url === "string" ? url.trim() : "";
|
|
737
713
|
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;
|
|
714
|
+
return context?.codeWidgetEmbedUrl ? context.codeWidgetEmbedUrl(u) : u;
|
|
715
|
+
}
|
|
716
|
+
function toCodeWidgetEmbedUrl(url) {
|
|
717
|
+
return typeof url === "string" ? url.trim() : "";
|
|
767
718
|
}
|
|
768
719
|
|
|
769
720
|
// src/schema/blocks/table.ts
|
|
@@ -2606,7 +2557,7 @@ var codeWidgetFormat = {
|
|
|
2606
2557
|
if (h && h !== "auto") styles.push(`height: ${/^\d+$/.test(h) ? h + "px" : h}`);
|
|
2607
2558
|
}
|
|
2608
2559
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
2609
|
-
const embedSrc =
|
|
2560
|
+
const embedSrc = resolveCodeWidgetEmbedSrc(src, context);
|
|
2610
2561
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
2611
2562
|
},
|
|
2612
2563
|
match(element) {
|
|
@@ -4103,7 +4054,10 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
|
|
|
4103
4054
|
return "";
|
|
4104
4055
|
}
|
|
4105
4056
|
const embedValue = value[embedType];
|
|
4106
|
-
const embedContext =
|
|
4057
|
+
const embedContext = {
|
|
4058
|
+
...options?.embed != null ? { embed: options.embed } : {},
|
|
4059
|
+
...options?.codeWidgetEmbedUrl != null ? { codeWidgetEmbedUrl: options.codeWidgetEmbedUrl } : {}
|
|
4060
|
+
};
|
|
4107
4061
|
const registry = options?.registry;
|
|
4108
4062
|
if (registry) {
|
|
4109
4063
|
const format = registry.get(embedType);
|
|
@@ -4937,7 +4891,8 @@ function deltaToMarkdown(delta, options = {}) {
|
|
|
4937
4891
|
prettyHtml = false,
|
|
4938
4892
|
registry,
|
|
4939
4893
|
softBreakStyle = "spaces",
|
|
4940
|
-
trimTrailingNewlines = false
|
|
4894
|
+
trimTrailingNewlines = false,
|
|
4895
|
+
codeWidgetEmbedUrl
|
|
4941
4896
|
} = options;
|
|
4942
4897
|
const useLatexDelimiters = mathSyntax === "latex";
|
|
4943
4898
|
const lines = splitIntoLines2(delta.ops);
|
|
@@ -4979,7 +4934,9 @@ function deltaToMarkdown(delta, options = {}) {
|
|
|
4979
4934
|
blockHandlers,
|
|
4980
4935
|
false,
|
|
4981
4936
|
registry,
|
|
4982
|
-
softBreakStyle
|
|
4937
|
+
softBreakStyle,
|
|
4938
|
+
false,
|
|
4939
|
+
codeWidgetEmbedUrl
|
|
4983
4940
|
)
|
|
4984
4941
|
).join("\n");
|
|
4985
4942
|
if (language === "math") {
|
|
@@ -5031,7 +4988,9 @@ ${code}
|
|
|
5031
4988
|
blockHandlers,
|
|
5032
4989
|
prettyHtml,
|
|
5033
4990
|
registry,
|
|
5034
|
-
softBreakStyle
|
|
4991
|
+
softBreakStyle,
|
|
4992
|
+
false,
|
|
4993
|
+
codeWidgetEmbedUrl
|
|
5035
4994
|
);
|
|
5036
4995
|
if (!content && !hasBlockFormat(attrs)) {
|
|
5037
4996
|
result.push(preserveEmptyLines ? "<br>" : "");
|
|
@@ -5255,7 +5214,7 @@ function getCodeBlockId2(attributes) {
|
|
|
5255
5214
|
const id = attributes["code-block-id"];
|
|
5256
5215
|
return typeof id === "string" ? id : void 0;
|
|
5257
5216
|
}
|
|
5258
|
-
function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false) {
|
|
5217
|
+
function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false, codeWidgetEmbedUrl) {
|
|
5259
5218
|
let result = "";
|
|
5260
5219
|
for (const op of ops) {
|
|
5261
5220
|
const attrs = op.attributes;
|
|
@@ -5277,7 +5236,8 @@ function renderLineContent2(ops, embedRenderers, inCodeBlock, useLatexDelimiters
|
|
|
5277
5236
|
prettyHtml,
|
|
5278
5237
|
registry,
|
|
5279
5238
|
softBreakStyle,
|
|
5280
|
-
inTableCell
|
|
5239
|
+
inTableCell,
|
|
5240
|
+
codeWidgetEmbedUrl
|
|
5281
5241
|
);
|
|
5282
5242
|
}
|
|
5283
5243
|
}
|
|
@@ -5311,7 +5271,7 @@ function renderInlineText2(text, attributes) {
|
|
|
5311
5271
|
}
|
|
5312
5272
|
return result;
|
|
5313
5273
|
}
|
|
5314
|
-
function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false) {
|
|
5274
|
+
function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = false, blockHandlers, prettyHtml = false, registry, softBreakStyle = "spaces", inTableCell = false, codeWidgetEmbedUrl) {
|
|
5315
5275
|
const entries = Object.entries(embed);
|
|
5316
5276
|
if (entries.length === 0) return "";
|
|
5317
5277
|
const firstEntry = entries[0];
|
|
@@ -5360,7 +5320,11 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
|
|
|
5360
5320
|
if (md !== null) return md;
|
|
5361
5321
|
}
|
|
5362
5322
|
if (format.render) {
|
|
5363
|
-
return format.render(
|
|
5323
|
+
return format.render(
|
|
5324
|
+
embedValue,
|
|
5325
|
+
attributes,
|
|
5326
|
+
codeWidgetEmbedUrl != null ? { codeWidgetEmbedUrl } : void 0
|
|
5327
|
+
);
|
|
5364
5328
|
}
|
|
5365
5329
|
}
|
|
5366
5330
|
}
|
|
@@ -5421,7 +5385,7 @@ function renderEmbed2(embed, attributes, customRenderers, useLatexDelimiters = f
|
|
|
5421
5385
|
if (h && h !== "auto") styles.push(`height: ${/^\d+$/.test(h) ? h + "px" : h}`);
|
|
5422
5386
|
}
|
|
5423
5387
|
const styleAttr = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
5424
|
-
const embedSrc =
|
|
5388
|
+
const embedSrc = codeWidgetEmbedUrl ? codeWidgetEmbedUrl(src) : src;
|
|
5425
5389
|
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${floatAttr}${styleAttr}></iframe>`;
|
|
5426
5390
|
}
|
|
5427
5391
|
return ``;
|
|
@@ -6415,6 +6379,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
|
|
|
6415
6379
|
parseScriderMarginEm,
|
|
6416
6380
|
preloadRemark,
|
|
6417
6381
|
renderDelta,
|
|
6382
|
+
resolveCodeWidgetEmbedSrc,
|
|
6418
6383
|
resolveDocumentPresentation,
|
|
6419
6384
|
resolveHeadingPolicy,
|
|
6420
6385
|
resolveTablePresentation,
|