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,