FMHYedit/.vitepress/markdown/toggleStarred.ts

18 lines
508 B
TypeScript
Raw 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">`
2023-11-12 16:42:57 +00:00
}
2024-07-10 04:05:54 +00:00
return self.renderToken(tokens, index, options)
2024-01-25 16:32:45 +00:00
}
2023-11-12 16:42:57 +00:00
}