Skip to content

Using "transformer" to add additional properties to markdown #2680

Answered by xarthurx
xarthurx asked this question in Q&A
Discussion options

You must be logged in to vote

I tried, but somehow it doesn't work for me.
In the end I come up with this solution:

export default defineTransformer({
	name: "md-transformer",
	extensions: [".md"],

	parse: async (_id: string, rawContent: string) => {
		// for debugging
		// console.log( "Raw content (first 10 characters):", rawContent.substring(0, 10));

		const parsedContent = await markdownParser.parse(_id, rawContent);
		const { content, data } = matter(rawContent);
    // console.log(content)

		return {
			...parsedContent,
			rawContent: content,
		};
	},
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@xarthurx
Comment options

Answer selected by xarthurx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants