@@ -30,7 +30,12 @@ export function snbtToDocument(raw: StringyMCText[]): JSONContent {
3030export function convertToTextOrEmpty ( raw : string ) : StringyMCText [ ] {
3131 if ( raw === "" ) return [ ] ;
3232
33+ // convert unquoted keys to quoted keys and unquoted string values to quoted string values
3334 raw = raw . replace ( / ( [ , { ] \s * ) ( [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * ) \s * : / g, '$1"$2":' ) ;
35+ raw = raw . replace (
36+ / (?< = [ { , ] \s * " [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * " \s * : \s * ) ( [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * ) / g,
37+ '"$1"' ,
38+ ) ;
3439
3540 if ( raw . match ( / ^ " \w * " / ) ) {
3641 return [ raw . replace ( / " / g, "" ) ] ;
@@ -47,12 +52,12 @@ export function convertToTextOrEmpty(raw: string): StringyMCText[] {
4752 } catch ( err ) {
4853 return [
4954 "" ,
50- { color :"red" , text :"An error occurred while parsing the SNBT." } ,
51- { color :"yellow" , text :" Please send the " } ,
52- { color :"gold" , text :"following error message" } ,
53- { color :"yellow" , text :" to Datapack Hub staff:\n" } ,
54- { color :"white" , bold :true , text :"Error: " } ,
55- { color :"gray" , text :err ! . toString ( ) }
55+ { color : "red" , text : "An error occurred while parsing the SNBT." } ,
56+ { color : "yellow" , text : " Please send the " } ,
57+ { color : "gold" , text : "following error message" } ,
58+ { color : "yellow" , text : " to Datapack Hub staff:\n" } ,
59+ { color : "white" , bold : true , text : "Error: " } ,
60+ { color : "gray" , text : err ! . toString ( ) } ,
5661 ] ;
5762 }
5863
@@ -84,53 +89,44 @@ function processTextComponent(text: StringyMCText, baseDocument: JSONContent) {
8489 finalText = applyStyling ( text , finalText ) ;
8590
8691 let paragraphContent = baseDocument . content ?. at ( - 1 ) ?. content ;
87-
88- if ( ! paragraphContent ) {
89- baseDocument . content ! . at ( - 1 ) ! . content = [ ] ;
90- paragraphContent = baseDocument . content ! . at ( - 1 ) ! . content ;
91- }
92-
9392 paragraphContent ! . push ( finalText ) ;
9493
9594 // Extra property
9695 if ( text . extra ) {
9796 text . extra ! . forEach ( ( txt ) => {
98- if ( typeof txt == "object" ) {
99- Object . assign ( txt , {
100- bold : txt . bold ?? text . bold ,
101- italic : txt . italic ?? text . italic ,
102- underlined : txt . underlined ?? text . underlined ,
103- obfuscated : txt . obfuscated ?? text . obfuscated ,
104- strikethrough : txt . strikethrough ?? text . strikethrough ,
105- color : txt . color ?? text . color ,
106- shadow_color : txt . shadow_color ?? text . shadow_color ,
107- click_event : txt . click_event ?? text . click_event ,
108- clickEvent : txt . clickEvent ?? text . clickEvent ,
109- hover_event : txt . hover_event ?? text . hover_event ,
110- hoverEvent : txt . hoverEvent ?? text . hoverEvent ,
111- font : txt . font ?? text . font ,
112- } ) ;
113- processTextComponent ( txt , baseDocument ) ;
114- } else {
115- let newComponent = {
116- text : txt ,
117- } ;
118- Object . assign ( newComponent , {
119- bold : text . bold ,
120- italic : text . italic ,
121- underlined : text . underlined ,
122- obfuscated : text . obfuscated ,
123- strikethrough : text . strikethrough ,
124- color : text . color ,
125- shadow_color : text . shadow_color ,
126- click_event : text . click_event ,
127- clickEvent : text . clickEvent ,
128- hover_event : text . hover_event ,
129- hoverEvent : text . hoverEvent ,
130- font : text . font ,
131- } ) ;
132- processTextComponent ( newComponent , baseDocument ) ;
133- }
97+ const newText = typeof txt === "object" ? { ...txt } : { text : txt } ;
98+ // Object.assign(newText, {
99+ // bold: text.bold,
100+ // italic: text.italic,
101+ // underlined: text.underlined,
102+ // obfuscated: text.obfuscated,
103+ // strikethrough: text.strikethrough,
104+ // color: text.color,
105+ // shadow_color: text.shadow_color,
106+ // click_event: text.click_event,
107+ // clickEvent: text.clickEvent,
108+ // hover_event: text.hover_event,
109+ // hoverEvent: text.hoverEvent,
110+ // font: text.font,
111+ // });
112+
113+ Object . assign ( newText , {
114+ bold : text . bold ?? newText . bold ,
115+ italic : text . italic ?? newText . italic ,
116+ underlined : text . underlined ?? newText . underlined ,
117+ obfuscated : text . obfuscated ?? newText . obfuscated ,
118+ strikethrough : text . strikethrough ?? newText . strikethrough ,
119+ color : text . color ?? newText . color ,
120+ shadow_color : text . shadow_color ?? newText . shadow_color ,
121+ click_event : text . click_event ?? newText . click_event ,
122+ clickEvent : text . clickEvent ?? newText . clickEvent ,
123+ hover_event : text . hover_event ?? newText . hover_event ,
124+ hoverEvent : text . hoverEvent ?? newText . hoverEvent ,
125+ font : text . font ?? newText . font ,
126+ } ) ;
127+
128+ console . log ( newText ) ;
129+ processTextComponent ( newText , baseDocument ) ;
134130 } ) ;
135131 }
136132}
@@ -244,9 +240,9 @@ function applyStyling(
244240 }
245241
246242 if ( text . font ) {
247- if ( finalText . marks . some ( ( mark ) => mark . type === "textStyle" ) ) {
248- finalText . marks . find ( ( mark ) => mark . type === " textStyle" ) ! . attrs ! . font =
249- text . font ;
243+ const textStyle = finalText . marks . find ( ( mark ) => mark . type === "textStyle" ) ;
244+ if ( textStyle ) {
245+ textStyle . attrs ! . font = text . font ;
250246 } else {
251247 finalText . marks ?. push ( {
252248 type : "textStyle" ,
0 commit comments