How can I replace frontmatter before parsing it? #1285
-
I have a situation where I have some markdown with yaml frontmatter, like this
Now lets say I change my document's title to
to this:
and then parse it. My Attempt
Notice the final output ( Why do I care?My goal is to replace the frontmatter and do some data processing without having to reconstruct the AST twice. Is there a way? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Welcome @ben519! 👋
Taking a step back, Markdown/CommonMark is a Markup language not a templating language. If you want to replace before parsing, another templating tool could be run first.
Modify the AST itself would be the ideal approach.
So others can get a sense of the versions of dependencies you are using? |
Beta Was this translation helpful? Give feedback.
Two things to note:
yaml
AST nodes do not include---
in their content, adding this in the replacement makes it invalidWorking example https://stackblitz.com/edit/node-ts1rqw
source from sandbox