mirror of
https://github.com/fmhy/edit.git
synced 2025-10-14 00:31:05 +11:00
Update toggleStarred.ts
This commit is contained in:
parent
ebc3109e47
commit
2463d980f5
1 changed files with 15 additions and 20 deletions
|
@ -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]
|
||||||
|
|
||||||
if (
|
// Ensure the token exists
|
||||||
!excluded.includes(env.frontmatter.title) &&
|
if (contentToken) {
|
||||||
contentToken &&
|
const content = contentToken.content
|
||||||
(
|
|
||||||
contentToken.content.includes(':star:') ||
|
|
||||||
contentToken.content.includes(':star2:')
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
// Create a copy to avoid modifying the original token directly, which can cause issues.
|
|
||||||
let content = contentToken.content;
|
|
||||||
|
|
||||||
// Replace :star2: FIRST to avoid conflicts
|
// Log the content for debugging purposes
|
||||||
content = content.replace(/:star2:/g, '<span class="star2">🌟</span>');
|
console.log('Content Token:', content)
|
||||||
content = content.replace(/:star:/g, '<span class="star">⭐</span>');
|
|
||||||
|
|
||||||
// Update the token's content
|
if (
|
||||||
contentToken.content = content;
|
!excluded.includes(env.frontmatter.title) &&
|
||||||
|
(content.includes('⭐') || content.includes('🌟')) // Directly check for emojis
|
||||||
return `<li class="starred">`;
|
) {
|
||||||
|
return `<li class="starred">`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self.renderToken(tokens, index, options);
|
|
||||||
};
|
return self.renderToken(tokens, index, options)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue