diff --git a/.changeset/silent-insects-explode.md b/.changeset/silent-insects-explode.md new file mode 100644 index 0000000..b7e2c71 --- /dev/null +++ b/.changeset/silent-insects-explode.md @@ -0,0 +1,5 @@ +--- +"astro-remote": patch +--- + +Fixes an issue with internal `dedent` function used for spacing/linebreak corrections for `Markdown` diff --git a/packages/astro-remote/lib/utils.ts b/packages/astro-remote/lib/utils.ts index 38d313c..d72a7e5 100644 --- a/packages/astro-remote/lib/utils.ts +++ b/packages/astro-remote/lib/utils.ts @@ -44,15 +44,15 @@ function getIndent(ln: string): string { } export function dedent(str: string): string { - const lns = str.replace(/^[\r\n]+/, "").split("\n"); - let indent = getIndent(lns[0]); - if (indent.length === 0 && lns.length > 1) { - indent = getIndent(lns[1]); - } - return lns - .map((ln) => (ln.startsWith(indent) ? ln.slice(indent.length) : ln)) - .map((ln, i, { length }) => (i === length - 1 ? ln.trim() : ln)) - .join("\n"); + const lns = str.replace(/^[\r\n]+/, "").split("\n"); + let indent = getIndent(lns[0]); + if (indent.length === 0 && lns.length > 1) { + indent = getIndent(lns[1]); + } + if (indent.length === 0) return lns.join("\n"); + return lns + .map(ln => ln.startsWith(indent) ? ln.slice(indent.length) : ln) + .join("\n"); } export interface HTMLOptions { diff --git a/packages/playground/src/pages/index.astro b/packages/playground/src/pages/index.astro index 57cf273..728a4ef 100644 --- a/packages/playground/src/pages/index.astro +++ b/packages/playground/src/pages/index.astro @@ -13,6 +13,7 @@