diff options
author | 2022-07-12 08:15:53 -0700 | |
---|---|---|
committer | 2022-07-12 11:15:53 -0400 | |
commit | 402c4181dcea8f7b741061452746f304cb952d77 (patch) | |
tree | 9ceab486a3d3570793f115d99a39ad355856de75 | |
parent | c2b14d525326407fd483f8ac1b06fb90725538c2 (diff) | |
download | astro-402c4181dcea8f7b741061452746f304cb952d77.tar.gz astro-402c4181dcea8f7b741061452746f304cb952d77.tar.zst astro-402c4181dcea8f7b741061452746f304cb952d77.zip |
Fix md mode comment (#3880)
* fix: fix a bug where md mode markdown breaks on comments
* chore: add changeset
-rw-r--r-- | .changeset/ten-frogs-mate.md | 5 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-markdown/index.ts | 10 |
2 files changed, 11 insertions, 4 deletions
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, |