File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -51,13 +51,21 @@ export function isMarkType(c: JSONContent, type: string) {
5151}
5252
5353export function unescapeUnicode ( str : string ) {
54- const matches = str . match ( / ( \\ u [ 0 - 9 a - f ] { 4 } ) / gi ) ;
54+ const regex = / \\ u (?: ( [ 0 - 9 a - f A - F ] { 4 } ) | \{ ( [ 0 - 9 a - f A - F ] + ) \} ) / g ;
5555
56- if ( ! matches ) {
57- return str
58- }
56+ return str . replace ( regex , ( match , p1 , p2 ) => {
57+ // p1 will contain the 4-digit hex if it's \uXXXX
58+ // p2 will contain the variable hex if it's \u{XXXXX}
59+ const hex = p1 || p2 ; // Get the hex value from whichever group matched
5960
60- return str . replaceAll ( / ( \\ u [ 0 - 9 a - f ] { 4 } ) / gi, decodeURIComponent ( JSON . parse ( `"${ matches ! [ 0 ] } "` ) ) ) ;
61+ if ( hex ) {
62+ const codePoint = parseInt ( hex , 16 ) ;
63+ return String . fromCodePoint ( codePoint ) ;
64+ }
65+ // If for some reason no hex was captured (shouldn't happen with this regex),
66+ // return the original match to avoid breaking the string.
67+ return match ;
68+ } ) ;
6169}
6270
6371/**
Original file line number Diff line number Diff line change 11import type { JSONContent } from "@tiptap/core" ;
2- import { colorMap , defaultColorLUT , trueMarkOrUndefined } from "./general" ;
2+ import { colorMap , defaultColorLUT , trueMarkOrUndefined , unescapeUnicode } from "./general" ;
33
44function hexToRgb ( hex : string ) : [ number , number , number ] {
55 hex = hex . replace ( / ^ # / , "" ) ;
@@ -76,7 +76,7 @@ export function translateMOTD(c: JSONContent) {
7676 let lowestDEVal = "" ;
7777 let formatting = ""
7878
79- const color = defaultColorLUT ( c . marks ?. at ( 0 ) ?. attrs ?. color ) ;
79+ const color = c . marks ?. at ( 0 ) ?. attrs ?. color ;
8080 for ( const c of colorMap ) {
8181 if ( ! color ) {
8282 continue ;
@@ -99,7 +99,7 @@ export function translateMOTD(c: JSONContent) {
9999 }
100100 }
101101
102- data += `${ char } r${ lowestDEVal } ${ formatting } ${ c . text } `
102+ data += `${ char } r${ lowestDEVal } ${ formatting } ${ unescapeUnicode ( c . text ) } `
103103 }
104104 if ( i < paragraphs . length - 1 ) data += "\\n" ;
105105 }
You can’t perform that action at this time.
0 commit comments