@mralfarrakhan/svork 0.6.0 → 0.6.2

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.
Files changed (2) hide show
  1. package/dist/index.mjs +7 -0
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -2311,6 +2311,9 @@ const maskMarkdownCodeForSvelteParse = (source) => {
2311
2311
  return chars.join("");
2312
2312
  };
2313
2313
  const escapeSvelteTextBraces = (value) => value.replace(/\{/g, "{").replace(/\}/g, "}");
2314
+ const escapeRawNodeBraces = (html) => {
2315
+ return html.replace(/"([^"]*)"/g, (match, val) => val.includes("<") ? `"${val.replace(/</g, "&lt;").replace(/>/g, "&gt;")}"` : match).split(/(<(?:script|style)\b[\s\S]*?<\/(?:script|style)\s*>)/gi).map((part, i) => i % 2 === 1 ? part : escapeSvelteTextBraces(part)).join("");
2316
+ };
2314
2317
  function escapeBracesPlugin() {
2315
2318
  return (tree) => {
2316
2319
  const SKIP = new Set(["script", "style"]);
@@ -2322,6 +2325,10 @@ function escapeBracesPlugin() {
2322
2325
  const visit = (node, ancestors) => {
2323
2326
  if (!node) return;
2324
2327
  if (node.type === "element") escapeProperties(node.properties);
2328
+ if (node.type === "raw" && typeof node.value === "string") {
2329
+ node.value = escapeRawNodeBraces(node.value);
2330
+ return;
2331
+ }
2325
2332
  if (node.type === "text") {
2326
2333
  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);
2327
2334
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mralfarrakhan/svork",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.6.2",
5
5
  "description": "Svelte utilities for writing blog",
6
6
  "author": "mralfarrakhan <alfarrakhan@gmail.com",
7
7
  "license": "AGPL-3.0-or-later",