Skip to content

Commit

Permalink
Markdoc: strip HTML comments from output (#7224)
Browse files Browse the repository at this point in the history
* feat: strip HTML comments from output

* chore: changeset
  • Loading branch information
bholmesdev authored May 31, 2023
1 parent 290e344 commit 563293c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/many-cats-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdoc': patch
---

Allow HTML comments `<!--like this-->` in Markdoc files.
9 changes: 8 additions & 1 deletion packages/integrations/markdoc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 563293c

Please sign in to comment.