FMHYedit/docs/.vitepress/markdown/toggleStarred.ts

19 lines
523 B
TypeScript
Raw Permalink Normal View History

2024-01-25 16:32:45 +00:00
import type { MarkdownRenderer } from 'vitepress'
2023-11-12 16:42:57 +00:00
2024-01-25 16:32:45 +00:00
const excluded = ['Beginners Guide']
2023-11-12 16:42:57 +00:00
export function toggleStarredPlugin(md: MarkdownRenderer) {
md.renderer.rules.list_item_open = (tokens, index, options, env, self) => {
2024-01-25 16:32:45 +00:00
const contentToken = tokens[index + 2]
2023-11-12 16:42:57 +00:00
if (
!excluded.includes(env.frontmatter.title) &&
contentToken &&
2024-01-25 16:32:45 +00:00
contentToken.content.startsWith(':star:')
2023-11-12 16:42:57 +00:00
) {
2024-01-25 16:32:45 +00:00
return `<li class="starred">`
} else {
2024-01-25 16:32:45 +00:00
return self.renderToken(tokens, index, options)
2023-11-12 16:42:57 +00:00
}
2024-01-25 16:32:45 +00:00
}
2023-11-12 16:42:57 +00:00
}