@mralfarrakhan/svork 0.5.0 → 0.6.1

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/README.md CHANGED
@@ -7,7 +7,7 @@ It is intended for blog/content pages where Markdown should stay ergonomic while
7
7
  ## Install
8
8
 
9
9
  ```sh
10
- bun add svork
10
+ bun add -D @mralfarrakhan/svork
11
11
  ```
12
12
 
13
13
  Svork has a peer dependency on Svelte 5.
@@ -21,7 +21,7 @@ import { svelteMarkdown } from "svork";
21
21
 
22
22
  export default {
23
23
  preprocess: [svelteMarkdown()],
24
- extensions: [".svelte", ".md"],
24
+ extensions: [".svx", ".md"],
25
25
  };
26
26
  ```
27
27
 
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.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
  }
@@ -2354,11 +2361,25 @@ const svelteMarkdown = (options) => {
2354
2361
  workingString = workingString.slice(fmMatch[0].length);
2355
2362
  }
2356
2363
  const finalize = async (markdownSource, placeholderMap = /* @__PURE__ */ new Map()) => {
2357
- let compiled = String(await mdCompiler.process(markdownSource));
2364
+ const vfile = await mdCompiler.process(markdownSource);
2365
+ let compiled = String(vfile);
2358
2366
  compiled = compiled.replace(/(&amp;#123;|&#x26;#123;)/g, "&#123;").replace(/(&amp;#125;|&#x26;#125;)/g, "&#125;");
2359
2367
  let restored = compiled;
2368
+ if (vfile.data?.fm && typeof vfile.data.fm === "object") metadata = {
2369
+ ...metadata,
2370
+ ...vfile.data.fm
2371
+ };
2360
2372
  const metadataString = `\nexport const metadata = ${JSON.stringify(metadata)};\n`;
2373
+ let hasModuleScript = false;
2361
2374
  for (const [placeholder, info] of placeholderMap.entries()) {
2375
+ if (info.type === "ModuleScript") {
2376
+ const scriptTagMatch = info.original.match(/^<script[^>]*>/);
2377
+ if (scriptTagMatch) {
2378
+ const injectIndex = scriptTagMatch[0].length;
2379
+ info.original = info.original.slice(0, injectIndex) + metadataString + info.original.slice(injectIndex);
2380
+ }
2381
+ hasModuleScript = true;
2382
+ }
2362
2383
  const escPlaceholder = escapeRegExp(placeholder);
2363
2384
  const markerPattern = `<svork-placeholder\\s+data-svork-id=(["'])${escPlaceholder}\\1[^>]*>[\\s\\S]*?<\\/svork-placeholder>`;
2364
2385
  const markerRegex = new RegExp(markerPattern, "g");
@@ -2395,7 +2416,7 @@ const svelteMarkdown = (options) => {
2395
2416
  }
2396
2417
  restored = restored.replace(new RegExp(placeholder, "g"), () => info.original);
2397
2418
  }
2398
- restored = `<script module lang="ts">${metadataString}<\/script>\n` + restored;
2419
+ if (!hasModuleScript) restored = `<script module lang="ts">${metadataString}<\/script>\n` + restored;
2399
2420
  return restored;
2400
2421
  };
2401
2422
  let root;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mralfarrakhan/svork",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.1",
5
5
  "description": "Svelte utilities for writing blog",
6
6
  "author": "mralfarrakhan <alfarrakhan@gmail.com",
7
7
  "license": "AGPL-3.0-or-later",
@@ -77,5 +77,8 @@
77
77
  "unist-util-stringify-position": "4.0.0",
78
78
  "vfile": "6.0.3",
79
79
  "vfile-message": "4.0.3"
80
+ },
81
+ "publishConfig": {
82
+ "access": "public"
80
83
  }
81
84
  }