From a6fc18e8bf96a6385599b241285fd2956ed8edf5 Mon Sep 17 00:00:00 2001 From: Ethan Shea Date: Wed, 1 May 2024 03:03:03 +0000 Subject: [PATCH] Frontmatter containing `$1` is correctly substituted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this change, the script itself would be inserted into the metadata string Before: ```svelte export const metadata = {"price":"0"}; const {·price·} = metadata; ``` After: --- packages/mdsvex/src/transformers/index.ts | 2 +- .../_fixtures/hybrid/input/dollar-one-in-frontmatter.svx | 5 +++++ .../_fixtures/hybrid/output/dollar-one-in-frontmatter.svelte | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 packages/mdsvex/test/_fixtures/hybrid/input/dollar-one-in-frontmatter.svx create mode 100644 packages/mdsvex/test/_fixtures/hybrid/output/dollar-one-in-frontmatter.svelte diff --git a/packages/mdsvex/src/transformers/index.ts b/packages/mdsvex/src/transformers/index.ts index a992fcca..f51fb617 100644 --- a/packages/mdsvex/src/transformers/index.ts +++ b/packages/mdsvex/src/transformers/index.ts @@ -380,7 +380,7 @@ export function transform_hast({ // @ts-ignore _module[0].value = _module[0].value.replace( RE_MODULE_SCRIPT, - `$1${newline}\t${fm}` + (match: string) => `${match}${newline}\t${fm}` ); } diff --git a/packages/mdsvex/test/_fixtures/hybrid/input/dollar-one-in-frontmatter.svx b/packages/mdsvex/test/_fixtures/hybrid/input/dollar-one-in-frontmatter.svx new file mode 100644 index 00000000..61127b3e --- /dev/null +++ b/packages/mdsvex/test/_fixtures/hybrid/input/dollar-one-in-frontmatter.svx @@ -0,0 +1,5 @@ +--- +price: '$10' +--- + \ No newline at end of file diff --git a/packages/mdsvex/test/_fixtures/hybrid/output/dollar-one-in-frontmatter.svelte b/packages/mdsvex/test/_fixtures/hybrid/output/dollar-one-in-frontmatter.svelte new file mode 100644 index 00000000..5ff48efc --- /dev/null +++ b/packages/mdsvex/test/_fixtures/hybrid/output/dollar-one-in-frontmatter.svelte @@ -0,0 +1,4 @@ +