meta data in markdown files #3290
Unanswered
4e576rt8uh9ij9okp
asked this question in
Q&A
Replies: 1 comment
-
You can use the preprocess hook to parse front-matter before the markdown import { marked } from 'marked';
import fm from 'front-matter';
// Override function
const hooks = {
preprocess(markdown) {
const { attributes, body } = fm(markdown);
for (const prop in attributes) {
if (prop in this.options) {
this.options[prop] = attributes[prop];
}
}
return body;
}
};
marked.use({ hooks });
// Run marked
console.log(marked.parse(`
---
headerIds: false
---
## test
`.trim())); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I want to add some meta data into the markdown files maybe something like:
How could I do this?
So anything below the
-----
lines would be parsed but anything above wouldn't, it would be just for the sake of getting the meta data.Or would it be better to just
.split("-----")
and then parse the meta data with my own function and pass the other half (markdown) to the marked parser?Beta Was this translation helpful? Give feedback.
All reactions