diff --git a/.changeset/many-cats-fry.md b/.changeset/many-cats-fry.md new file mode 100644 index 000000000000..75ebfe5014b2 --- /dev/null +++ b/.changeset/many-cats-fry.md @@ -0,0 +1,5 @@ +--- +'@astrojs/markdoc': patch +--- + +Allow HTML comments `` in Markdoc files. diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index 17f0123606d2..f33c3a1be5b6 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -19,6 +19,12 @@ type SetupHookParams = HookParameters<'astro:config:setup'> & { addContentEntryType: (contentEntryType: ContentEntryType) => void; }; +const markdocTokenizer = new Markdoc.Tokenizer({ + // Strip from rendered output + // Without this, they're rendered as strings! + allowComments: true, +}); + export default function markdocIntegration(legacyConfig?: any): AstroIntegration { if (legacyConfig) { console.log( @@ -64,7 +70,8 @@ export default function markdocIntegration(legacyConfig?: any): AstroIntegration getEntryInfo, async getRenderModule({ contents, fileUrl, viteId }) { const entry = getEntryInfo({ contents, fileUrl }); - const ast = Markdoc.parse(entry.body); + const tokens = markdocTokenizer.tokenize(entry.body); + const ast = Markdoc.parse(tokens); const pluginContext = this; const markdocConfig = await setupConfig(userMarkdocConfig);