Markdoc: strip HTML comments from output (#7224)
* feat: strip HTML comments from output * chore: changeset
This commit is contained in:
parent
290e344dee
commit
563293c5d6
2 changed files with 13 additions and 1 deletions
5
.changeset/many-cats-fry.md
Normal file
5
.changeset/many-cats-fry.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/markdoc': patch
|
||||
---
|
||||
|
||||
Allow HTML comments `<!--like this-->` in Markdoc files.
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue