Update toggleStarred.ts

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

View file

@ -19,28 +19,23 @@ 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]
// Ensure the token exists
if (contentToken) {
const content = contentToken.content
// Log the content for debugging purposes
console.log('Content Token:', content)
if ( if (
!excluded.includes(env.frontmatter.title) && !excluded.includes(env.frontmatter.title) &&
contentToken && (content.includes('⭐') || content.includes('🌟')) // Directly check for emojis
(
contentToken.content.includes(':star:') ||
contentToken.content.includes(':star2:')
)
) { ) {
// Create a copy to avoid modifying the original token directly, which can cause issues. return `<li class="starred">`
let content = contentToken.content; }
}
// Replace :star2: FIRST to avoid conflicts
content = content.replace(/:star2:/g, '<span class="star2">🌟</span>'); return self.renderToken(tokens, index, options)
content = content.replace(/:star:/g, '<span class="star">⭐</span>');
// Update the token's content
contentToken.content = content;
return `<li class="starred">`;
} }
return self.renderToken(tokens, index, options);
};
} }