@@ -150,26 +150,23 @@ async function setFont(name) {
150150 ) ;
151151 let css = get ( name ) ;
152152
153- // get all url font css
154- const urls = / u r l \( ( .* ?) \) / g. exec ( css ) ?. slice ( 1 ) ;
155-
156- await Promise . all (
157- urls ?. map ( async ( url ) => {
158- if ( ! / ^ h t t p s ? / . test ( url ) ) return ;
159- if ( / ^ h t t p s ? : \/ \/ l o c a l h o s t / ) return ;
160- const fontFile = await downloadFont ( name , url ) ;
161- const internalUrl = await helpers . toInternalUri ( fontFile ) ;
162- css = css . replace ( url , internalUrl ) ;
163- } ) ,
164- ) ;
165-
166- $style . textContent = `${ css }
153+ // Get all URL font references
154+ const urls = [ ...css . matchAll ( / u r l \( ( .* ?) \) / g) ] . map ( ( match ) => match [ 1 ] ) ;
155+
156+ urls ?. map ( async ( url ) => {
157+ if ( ! / ^ h t t p s ? / . test ( url ) ) return ;
158+ if ( / ^ h t t p s ? : \/ \/ l o c a l h o s t / . test ( url ) ) return ;
159+ const fontFile = await downloadFont ( name , url ) ;
160+ const internalUrl = await helpers . toInternalUri ( fontFile ) ;
161+ css = css . replace ( url , internalUrl ) ;
162+ } ) ,
163+ ( $style . textContent = `${ css }
167164 .editor-container.ace_editor{
168165 font-family: "${ name } ", NotoMono, Monaco, MONOSPACE !important;
169166 }
170167 .ace_text{
171168 font-family: inherit !important;
172- }` ;
169+ }` ) ;
173170 document . head . append ( $style ) ;
174171 } catch ( error ) {
175172 toast ( `${ name } font not found` , "error" ) ;
@@ -191,6 +188,7 @@ async function downloadFont(name, link) {
191188 }
192189
193190 const font = await fsOperation ( link ) . readFile ( ) ;
191+ console . log ( "fonts content : " , font ) ;
194192 await fsOperation ( FONT_DIR ) . createFile ( name , font ) ;
195193
196194 return FONT_FILE ;
0 commit comments