Update toggleStarred.ts

This commit is contained in:
nbats 2025-01-21 22:40:21 -08:00 committed by GitHub
parent b866a618a1
commit ebc3109e47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,7 +19,8 @@ const excluded = ['Beginners Guide']
export function toggleStarredPlugin(md: MarkdownRenderer) { export function toggleStarredPlugin(md: MarkdownRenderer) {
md.renderer.rules.list_item_open = (tokens, index, options, env, self) => { md.renderer.rules.list_item_open = (tokens, index, options, env, self) => {
const contentToken = tokens[index + 2] const contentToken = tokens[index + 2];
if ( if (
!excluded.includes(env.frontmatter.title) && !excluded.includes(env.frontmatter.title) &&
contentToken && contentToken &&
@ -28,10 +29,15 @@ export function toggleStarredPlugin(md: MarkdownRenderer) {
contentToken.content.includes(':star2:') contentToken.content.includes(':star2:')
) )
) { ) {
// Replace the placeholders with HTML // Create a copy to avoid modifying the original token directly, which can cause issues.
contentToken.content = contentToken.content let content = contentToken.content;
.replace(':star:', '<span class="star">⭐</span>') // Use HTML for star
.replace(':star2:', '<span class="star2">🌟</span>'); // Use HTML for star2 // Replace :star2: FIRST to avoid conflicts
content = content.replace(/:star2:/g, '<span class="star2">🌟</span>');
content = content.replace(/:star:/g, '<span class="star">⭐</span>');
// Update the token's content
contentToken.content = content;
return `<li class="starred">`; return `<li class="starred">`;
} }