From 402c4181dcea8f7b741061452746f304cb952d77 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Tue, 12 Jul 2022 08:15:53 -0700 Subject: [PATCH] Fix md mode comment (#3880) * fix: fix a bug where md mode markdown breaks on comments * chore: add changeset --- .changeset/ten-frogs-mate.md | 5 +++++ packages/astro/src/vite-plugin-markdown/index.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/ten-frogs-mate.md diff --git a/.changeset/ten-frogs-mate.md b/.changeset/ten-frogs-mate.md new file mode 100644 index 000000000..20e44fa6b --- /dev/null +++ b/.changeset/ten-frogs-mate.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix rendering HTML comments in `mode="md"` configuration diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index ffaa8afc7..8bf274329 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -148,10 +148,12 @@ export default function markdown({ config }: AstroPluginOptions): Plugin { // Turn HTML comments into JS comments while preventing nested `*/` sequences // from ending the JS comment by injecting a zero-width space // Inside code blocks, this is removed during renderMarkdown by the remark-escape plugin. - markdownContent = markdownContent.replace( - /<\s*!--([^-->]*)(.*?)-->/gs, - (whole) => `{/*${whole.replace(/\*\//g, '*\u200b/')}*/}` - ); + if (renderOpts.mode === 'mdx') { + markdownContent = markdownContent.replace( + /<\s*!--([^-->]*)(.*?)-->/gs, + (whole) => `{/*${whole.replace(/\*\//g, '*\u200b/')}*/}` + ); + } let renderResult = await renderMarkdown(markdownContent, { ...renderOpts,