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;