From 689c8194752ef1dcc6217cafb031b2d8ec55927d Mon Sep 17 00:00:00 2001 From: chelkyl <14041823+chelkyl@users.noreply.github.com> Date: Thu, 2 May 2024 12:24:05 -0500 Subject: [PATCH] fix: errant slice for trailing whitespace (#28) --- .changeset/selfish-radios-talk.md | 5 +++++ packages/astro-remote/lib/utils.ts | 4 ++-- packages/playground/src/pages/index.astro | 3 ++- .../playground/src/pages/test-issue27.astro | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .changeset/selfish-radios-talk.md create mode 100644 packages/playground/src/pages/test-issue27.astro diff --git a/.changeset/selfish-radios-talk.md b/.changeset/selfish-radios-talk.md new file mode 100644 index 0000000..7874be8 --- /dev/null +++ b/.changeset/selfish-radios-talk.md @@ -0,0 +1,5 @@ +--- +"astro-remote": patch +--- + +Fixes an issue with internal `getIndent` function used for spacing corrections for `Markdown` diff --git a/packages/astro-remote/lib/utils.ts b/packages/astro-remote/lib/utils.ts index d72a7e5..20ff43f 100644 --- a/packages/astro-remote/lib/utils.ts +++ b/packages/astro-remote/lib/utils.ts @@ -39,8 +39,8 @@ export function createComponentProxy( } function getIndent(ln: string): string { - if (ln.trim() === ln) return ""; - return ln.slice(0, ln.length - ln.trim().length); + if (ln.trimStart() === ln) return ""; + return ln.slice(0, ln.length - ln.trimStart().length); } export function dedent(str: string): string { diff --git a/packages/playground/src/pages/index.astro b/packages/playground/src/pages/index.astro index 728a4ef..dba53b1 100644 --- a/packages/playground/src/pages/index.astro +++ b/packages/playground/src/pages/index.astro @@ -14,6 +14,7 @@

Remote:

- \ No newline at end of file + diff --git a/packages/playground/src/pages/test-issue27.astro b/packages/playground/src/pages/test-issue27.astro new file mode 100644 index 0000000..e16de1f --- /dev/null +++ b/packages/playground/src/pages/test-issue27.astro @@ -0,0 +1,18 @@ +--- +import { Markdown } from "astro-remote"; +--- + + + + + + + + Astro + + + Highlighted word with no trailing space"} /> + Highlighted word with trailing space "} /> + Highlighted word with trailing spaces "} /> + +