From 87231b1168da66bb593f681206c42fa555dfcabc Mon Sep 17 00:00:00 2001 From: Sean van Zuidam Date: Thu, 5 Dec 2024 15:50:17 +0100 Subject: [PATCH] Bugfix/extra whitespace in code (#12570) Co-authored-by: Bjorn Lu --- .changeset/twelve-pens-remain.md | 5 +++++ packages/markdown/remark/src/shiki.ts | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/twelve-pens-remain.md diff --git a/.changeset/twelve-pens-remain.md b/.changeset/twelve-pens-remain.md new file mode 100644 index 0000000000..46023ea725 --- /dev/null +++ b/.changeset/twelve-pens-remain.md @@ -0,0 +1,5 @@ +--- +"@astrojs/markdown-remark": patch +--- + +Removes trailing new line in code blocks to prevent generating a trailing empty `` tag diff --git a/packages/markdown/remark/src/shiki.ts b/packages/markdown/remark/src/shiki.ts index ed4daf527a..b8284c471b 100644 --- a/packages/markdown/remark/src/shiki.ts +++ b/packages/markdown/remark/src/shiki.ts @@ -103,6 +103,8 @@ export async function createShikiHighlighter({ } } + code = code.replace(/(?:\r\n|\r|\n)$/, ''); + const themeOptions = Object.values(themes).length ? { themes } : { theme }; const inline = options?.inline ?? false;