@@ -57,6 +57,72 @@ function escapeRegExp(value: string): string {
5757 return value . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
5858}
5959
60+ async function shouldAutoCloseTags ( ) : Promise < boolean > {
61+ const { default : appSettings } = await import ( "lib/settings" ) ;
62+ return appSettings . value . autoCloseTags !== false ;
63+ }
64+
65+ function createLanguageLoader ( name : string , lang : LanguageDescription ) {
66+ const normalizedName = normalizeModeKey ( name ) ;
67+
68+ switch ( normalizedName ) {
69+ case "html" :
70+ return async ( ) => {
71+ const { html } = await import ( "@codemirror/lang-html" ) ;
72+ return html ( { autoCloseTags : await shouldAutoCloseTags ( ) } ) ;
73+ } ;
74+
75+ case "xml" :
76+ return async ( ) => {
77+ const { xml } = await import ( "@codemirror/lang-xml" ) ;
78+ return xml ( { autoCloseTags : await shouldAutoCloseTags ( ) } ) ;
79+ } ;
80+
81+ case "vue" :
82+ return async ( ) => {
83+ const [ { vue } , { html } ] = await Promise . all ( [
84+ import ( "@codemirror/lang-vue" ) ,
85+ import ( "@codemirror/lang-html" ) ,
86+ ] ) ;
87+ return vue ( {
88+ base : html ( { autoCloseTags : await shouldAutoCloseTags ( ) } ) ,
89+ } ) ;
90+ } ;
91+
92+ case "angular" :
93+ return async ( ) => {
94+ const [ { angular } , { html } ] = await Promise . all ( [
95+ import ( "@codemirror/lang-angular" ) ,
96+ import ( "@codemirror/lang-html" ) ,
97+ ] ) ;
98+ return angular ( {
99+ base : html ( {
100+ autoCloseTags : await shouldAutoCloseTags ( ) ,
101+ selfClosingTags : true ,
102+ } ) ,
103+ } ) ;
104+ } ;
105+
106+ case "php" :
107+ return async ( ) => {
108+ const [ { php } , { html } ] = await Promise . all ( [
109+ import ( "@codemirror/lang-php" ) ,
110+ import ( "@codemirror/lang-html" ) ,
111+ ] ) ;
112+ const htmlSupport = html ( {
113+ autoCloseTags : await shouldAutoCloseTags ( ) ,
114+ matchClosingTags : false ,
115+ } ) ;
116+ return [
117+ php ( { baseLanguage : htmlSupport . language } ) ,
118+ htmlSupport . support ,
119+ ] ;
120+ } ;
121+ }
122+
123+ return typeof lang . load === "function" ? ( ) => lang . load ! ( ) : null ;
124+ }
125+
60126// 1) Always register a plain text fallback
61127addMode ( "Text" , "txt|text|log|plain" , "Plain Text" , ( ) => [ ] ) ;
62128
@@ -106,7 +172,7 @@ for (const lang of languages as readonly LanguageDescription[]) {
106172
107173 // Wrap language-data loader as our modelist language provider
108174 // lang.load() returns a Promise<Extension>; we let the editor handle async loading
109- const loader = typeof lang . load === "function" ? ( ) => lang . load ! ( ) : null ;
175+ const loader = createLanguageLoader ( name , lang ) ;
110176
111177 addMode ( modeId , pattern , name , loader , {
112178 aliases,
0 commit comments