File tree Expand file tree Collapse file tree
.vitepress/theme/components/js Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 * 无法使用 Vue 组件或 data-* 属性。故在运行时用 JS 检测 emoji 并包装。
1010 */
1111
12+ /**
13+ * 匹配开头的单个 emoji 簇(含 ZWJ 序列、肤色修饰符、FE0F 变体选择器)。
14+ * 例如 🧑🌾(person + ZWJ + ear of rice)会被视为一个完整 emoji,
15+ * 避免被拆成 🧑 和 🌾 两个图标。
16+ */
17+ const leadingEmojiRegex = / ^ ( \p{ Emoji_Presentation} | \p{ Extended_Pictographic} \uFE0F ? ) (?: \p{ Emoji_Modifier} ) ? (?: \u200D ( \p{ Emoji_Presentation} | \p{ Extended_Pictographic} \uFE0F ? ) (?: \p{ Emoji_Modifier} ) ? ) * / u;
18+
1219/**
1320 * 检查字符串开头是否为 emoji
1421 */
1522function hasLeadingEmoji ( text ) {
16- const emojiRegex = / ^ ( \p{ Emoji_Presentation} | \p{ Extended_Pictographic} \uFE0F ? | \p{ Emoji} \u200D [ \p{ Emoji} \p{ Extended_Pictographic} ] | \p{ Emoji} \uFE0F ) / u;
17- return emojiRegex . test ( text ) ;
23+ return leadingEmojiRegex . test ( text ) ;
1824}
1925
2026/**
2127 * 提取开头的 emoji 字符
2228 */
2329function extractLeadingEmoji ( text ) {
24- const match = text . match ( / ^ ( \p { Emoji_Presentation } | \p { Extended_Pictographic } \uFE0F ? | \p { Emoji } \u200D [ \p { Emoji } \p { Extended_Pictographic } ] | \p { Emoji } \uFE0F ? ) / u ) ;
30+ const match = text . match ( leadingEmojiRegex ) ;
2531 if ( match ) {
2632 return { emoji : match [ 0 ] , text : text . slice ( match [ 0 ] . length ) . trim ( ) } ;
2733 }
You can’t perform that action at this time.
0 commit comments