@@ -16,6 +16,7 @@ class CodeElement extends EventTarget {
1616 this . el = el ;
1717 this . mode = mode ;
1818 this . executeFunc = executeFunc ;
19+ this . fixFormatting ( ) ;
1920 this . listen ( ) ;
2021 }
2122
@@ -48,7 +49,6 @@ class CodeElement extends EventTarget {
4849 // init editor on first focus
4950 this . onFocus = this . initEditor . bind ( this ) ;
5051 this . el . addEventListener ( "focus" , this . onFocus ) ;
51- setTimeout ( ( ) => this . fixFormatting ( ) , 0 ) ;
5252 }
5353
5454 // initEditor removes prepares the code snippet
@@ -105,12 +105,14 @@ class CodeElement extends EventTarget {
105105 // fixFormatting removes invalid formatting from the code,
106106 // while preserving the syntax highlighting.
107107 fixFormatting ( ) {
108- this . el . innerHTML = this . el . innerHTML
109- // Docusaurus uses <br> for new lines inside code blocks,
110- // so we need to replace it with \n
111- . replaceAll ( "<br>" , "\n" )
112- // convert non-breaking spaces to normal ones
113- . replace ( / [ \u00A0 ] / g, " " ) ;
108+ setTimeout ( ( ) => {
109+ this . el . innerHTML = this . el . innerHTML
110+ // Docusaurus uses <br> for new lines inside code blocks,
111+ // so we need to replace it with \n
112+ . replaceAll ( "<br>" , "\n" )
113+ // convert non-breaking spaces to normal ones
114+ . replace ( / [ \u00A0 ] / g, " " ) ;
115+ } , 0 ) ;
114116 }
115117
116118 // focusEnd sets the cursor to the end of the element's content.
0 commit comments