mirror of
https://github.com/fmhy/edit.git
synced 2026-02-18 09:11:33 +11:00
comment
This commit is contained in:
parent
ce817ee383
commit
2a6f2fb9f1
1 changed files with 13 additions and 1 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
import { icons as twemoji } from '@iconify-json/twemoji'
|
import { icons as twemoji } from '@iconify-json/twemoji'
|
||||||
import type { MarkdownRenderer } from 'vitepress'
|
import type { MarkdownRenderer } from 'vitepress'
|
||||||
|
|
||||||
|
// This object contains all the emoji definitions from the twemoji library
|
||||||
|
// Each key in the object corresponds to an emoji name and its value is an empty string
|
||||||
export const defs = {
|
export const defs = {
|
||||||
...Object.fromEntries(
|
...Object.fromEntries(
|
||||||
Object.entries(twemoji.icons).map(([key]) => {
|
Object.entries(twemoji.icons).map(([key]) => {
|
||||||
|
|
@ -9,27 +11,36 @@ export const defs = {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function modifies the MarkdownRenderer to render emojis using the Twemoji library
|
||||||
|
// It sets the 'emoji' rule for the renderer to replace emoji markup with Twemoji SVG icons
|
||||||
export function emojiRender(md: MarkdownRenderer) {
|
export function emojiRender(md: MarkdownRenderer) {
|
||||||
md.renderer.rules.emoji = (tokens, idx) => {
|
md.renderer.rules.emoji = (tokens, idx) => {
|
||||||
|
// If the emoji markup starts with 'star', add a 'starred' class to the icon
|
||||||
if (tokens[idx].markup.startsWith('star')) {
|
if (tokens[idx].markup.startsWith('star')) {
|
||||||
return `<span class="i-twemoji-${tokens[idx].markup} starred"></span>`
|
return `<span class="i-twemoji-${tokens[idx].markup} starred"></span>`
|
||||||
}
|
}
|
||||||
|
// Otherwise, just add the Twemoji class to the icon
|
||||||
return `<span class="i-twemoji-${tokens[idx].markup}"></span>`
|
return `<span class="i-twemoji-${tokens[idx].markup}"></span>`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function moves a plugin to a specific position in the plugins array
|
||||||
|
// It takes the plugins array, the name of the plugin to move, the order (before or after), and the name of the target plugin
|
||||||
export function movePlugin(
|
export function movePlugin(
|
||||||
plugins: { name: string }[],
|
plugins: { name: string }[],
|
||||||
pluginAName: string,
|
pluginAName: string,
|
||||||
order: 'before' | 'after',
|
order: 'before' | 'after',
|
||||||
pluginBName: string
|
pluginBName: string
|
||||||
) {
|
) {
|
||||||
|
// Find the index of the target plugin
|
||||||
const pluginBIndex = plugins.findIndex((p) => p.name === pluginBName)
|
const pluginBIndex = plugins.findIndex((p) => p.name === pluginBName)
|
||||||
if (pluginBIndex === -1) return
|
if (pluginBIndex === -1) return
|
||||||
|
|
||||||
|
// Find the index of the plugin to move
|
||||||
const pluginAIndex = plugins.findIndex((p) => p.name === pluginAName)
|
const pluginAIndex = plugins.findIndex((p) => p.name === pluginAName)
|
||||||
if (pluginAIndex === -1) return
|
if (pluginAIndex === -1) return
|
||||||
|
|
||||||
|
// Move the plugin to the specified position
|
||||||
if (order === 'before' && pluginAIndex > pluginBIndex) {
|
if (order === 'before' && pluginAIndex > pluginBIndex) {
|
||||||
const pluginA = plugins.splice(pluginAIndex, 1)[0]
|
const pluginA = plugins.splice(pluginAIndex, 1)[0]
|
||||||
plugins.splice(pluginBIndex, 0, pluginA)
|
plugins.splice(pluginBIndex, 0, pluginA)
|
||||||
|
|
@ -37,6 +48,7 @@ export function movePlugin(
|
||||||
|
|
||||||
if (order === 'after' && pluginAIndex < pluginBIndex) {
|
if (order === 'after' && pluginAIndex < pluginBIndex) {
|
||||||
const pluginA = plugins.splice(pluginAIndex, 1)[0]
|
const pluginA = plugins.splice(pluginAIndex, 1)[0]
|
||||||
plugins.splice(pluginBIndex, 0, pluginA)
|
plugins.splice(pluginBIndex + 1, 0, pluginA)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue