mirror of
https://github.com/fmhy/edit.git
synced 2025-10-13 08:11:07 +11:00
Update toggleStarred.ts
This commit is contained in:
parent
b866a618a1
commit
ebc3109e47
1 changed files with 11 additions and 5 deletions
|
@ -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">`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue