Skip to content

multiple instances when using markdown-it as a plugin #756

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

You must be logged in to vote

Move your highlight instance out off the NuxtPlugin object like:

  const highlighter = await mdShiki({
				themes: {
					light: "snazzy-light",
					dark: "nord",
				},
			})
			

export default defineNuxtPlugin(async () => {
	const renderer = MarkdownIt({
		linkify: true,
		html: true,
	})
		.use(footnote)
		.use(highlighter)

	return {
		provide: {
			md: renderer,
		},
	};
});

Keeping it in the NuxtPlugin means its going to get called over and over, just move it up to a constant at the top of the file and it will only be created once (singleton).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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