Markdoc: strip HTML comments from output (#7224)

* feat: strip HTML comments from output

* chore: changeset
This commit is contained in:
Ben Holmes 2023-05-31 10:09:49 -04:00 committed by GitHub
parent 290e344dee
commit 563293c5d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/markdoc': patch
---
Allow HTML comments `<!--like this-->` in Markdoc files.

View file

@ -19,6 +19,12 @@ type SetupHookParams = HookParameters<'astro:config:setup'> & {
addContentEntryType: (contentEntryType: ContentEntryType) => void;
};
const markdocTokenizer = new Markdoc.Tokenizer({
// Strip <!-- comments --> 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);