@mralfarrakhan/svork 0.6.4 → 0.6.6
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.mjs +1 -17
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2245,8 +2245,7 @@ const getPlaceholderReplacement = (token, type, original) => {
|
|
|
2245
2245
|
return `<svork-placeholder data-svork-id="${escapeHtmlAttribute(token)}">${escapeHtmlText(surrogate)}</svork-placeholder>`;
|
|
2246
2246
|
};
|
|
2247
2247
|
const isSvelteAttribute = (attr) => {
|
|
2248
|
-
if (!attr) return
|
|
2249
|
-
if (attr.type !== "Attribute") return true;
|
|
2248
|
+
if (!attr || attr.type !== "Attribute") return true;
|
|
2250
2249
|
if (Array.isArray(attr.value)) return attr.value.some((valueNode) => valueNode?.type !== "Text");
|
|
2251
2250
|
return attr.value?.type === "ExpressionTag";
|
|
2252
2251
|
};
|
|
@@ -2312,9 +2311,6 @@ const maskMarkdownCodeForSvelteParse = (source) => {
|
|
|
2312
2311
|
return chars.join("");
|
|
2313
2312
|
};
|
|
2314
2313
|
const escapeSvelteTextBraces = (value) => value.replace(/\{/g, "{").replace(/\}/g, "}");
|
|
2315
|
-
const escapeRawNodeBraces = (html) => {
|
|
2316
|
-
return html.replace(/"([^"]*)"/g, (match, val) => val.includes("<") ? `"${val.replace(/</g, "<").replace(/>/g, ">")}"` : match).replace(/'([^']*)'/g, (match, val) => val.includes("<") ? `'${val.replace(/</g, "<").replace(/>/g, ">")}'` : match).split(/(<(?:script|style)\b[\s\S]*?<\/(?:script|style)\s*>)/gi).map((part, i) => i % 2 === 1 ? part : escapeSvelteTextBraces(part)).join("");
|
|
2317
|
-
};
|
|
2318
2314
|
function escapeBracesPlugin() {
|
|
2319
2315
|
return (tree) => {
|
|
2320
2316
|
const SKIP = new Set(["script", "style"]);
|
|
@@ -2326,10 +2322,6 @@ function escapeBracesPlugin() {
|
|
|
2326
2322
|
const visit = (node, ancestors) => {
|
|
2327
2323
|
if (!node) return;
|
|
2328
2324
|
if (node.type === "element") escapeProperties(node.properties);
|
|
2329
|
-
if (node.type === "raw" && typeof node.value === "string") {
|
|
2330
|
-
node.value = escapeRawNodeBraces(node.value);
|
|
2331
|
-
return;
|
|
2332
|
-
}
|
|
2333
2325
|
if (node.type === "text") {
|
|
2334
2326
|
if (!ancestors.some((a) => a?.type === "element" && typeof a.tagName === "string" && SKIP.has(a.tagName)) && typeof node.value === "string" && (node.value.includes("{") || node.value.includes("}"))) node.value = escapeSvelteTextBraces(node.value);
|
|
2335
2327
|
}
|
|
@@ -2365,14 +2357,6 @@ const svelteMarkdown = (options) => {
|
|
|
2365
2357
|
const vfile = await mdCompiler.process(markdownSource);
|
|
2366
2358
|
let compiled = String(vfile);
|
|
2367
2359
|
compiled = compiled.replace(/(&#123;|&#123;)/g, "{").replace(/(&#125;|&#125;)/g, "}");
|
|
2368
|
-
const escapeAttrVal = (val) => val.replace(/</g, "<").replace(/>/g, ">").replace(/\{/g, "{").replace(/\}/g, "}");
|
|
2369
|
-
compiled = compiled.replace(/"([^"]*)"/g, (match, val) => {
|
|
2370
|
-
if (!val.includes("<") && !val.includes("{") && !val.includes("}")) return match;
|
|
2371
|
-
return `"${escapeAttrVal(val)}"`;
|
|
2372
|
-
}).replace(/'([^']*)'/g, (match, val) => {
|
|
2373
|
-
if (!val.includes("<") && !val.includes("{") && !val.includes("}")) return match;
|
|
2374
|
-
return `'${escapeAttrVal(val)}'`;
|
|
2375
|
-
});
|
|
2376
2360
|
let restored = compiled;
|
|
2377
2361
|
if (vfile.data?.fm && typeof vfile.data.fm === "object") metadata = {
|
|
2378
2362
|
...metadata,
|
package/package.json
CHANGED