Fix md mode comment (#3880)

* fix: fix a bug where md mode markdown breaks on comments

* chore: add changeset
This commit is contained in:
Corbin Crutchley 2022-07-12 08:15:53 -07:00 committed by GitHub
parent c2b14d5253
commit 402c4181dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix rendering HTML comments in `mode="md"` configuration

View file

@ -148,10 +148,12 @@ export default function markdown({ config }: AstroPluginOptions): Plugin {
// Turn HTML comments into JS comments while preventing nested `*/` sequences // Turn HTML comments into JS comments while preventing nested `*/` sequences
// from ending the JS comment by injecting a zero-width space // from ending the JS comment by injecting a zero-width space
// Inside code blocks, this is removed during renderMarkdown by the remark-escape plugin. // Inside code blocks, this is removed during renderMarkdown by the remark-escape plugin.
markdownContent = markdownContent.replace( if (renderOpts.mode === 'mdx') {
/<\s*!--([^-->]*)(.*?)-->/gs, markdownContent = markdownContent.replace(
(whole) => `{/*${whole.replace(/\*\//g, '*\u200b/')}*/}` /<\s*!--([^-->]*)(.*?)-->/gs,
); (whole) => `{/*${whole.replace(/\*\//g, '*\u200b/')}*/}`
);
}
let renderResult = await renderMarkdown(markdownContent, { let renderResult = await renderMarkdown(markdownContent, {
...renderOpts, ...renderOpts,