@@ -11,6 +11,7 @@ import { markdown } from "@codemirror/lang-markdown";
1111import { xml } from "@codemirror/lang-xml" ;
1212import { yaml } from "@codemirror/lang-yaml" ;
1313import { latex } from "codemirror-lang-latex" ;
14+ import { typst } from "codemirror-lang-typst" ;
1415
1516const languageMap = {
1617 // Official CodeMirror languages
@@ -22,14 +23,15 @@ const languageMap = {
2223 yaml,
2324 // Unofficial 3rd party languages
2425 latex,
26+ typst,
2527 // Aliases to near-matches
2628 pagedjs : html ,
2729 sile : latex ,
2830 weasyprint : html ,
2931 xelatex : latex ,
3032} ;
3133
32- window . initCodeMirror = async function ( element , content , language ) {
34+ export async function initCodeMirror ( element , content , language ) {
3335 let polyTheme = EditorView . baseTheme ( {
3436 "&light" : {
3537 backgroundColor : "#fff" ,
@@ -39,27 +41,12 @@ window.initCodeMirror = async function (element, content, language) {
3941 } ,
4042 } ) ;
4143
42- let languageExtension = [ ] ;
43- const spec = languageMap [ language ] ;
44- if ( spec ) {
45- const ext = spec ( ) ;
46- languageExtension = ext instanceof Promise ? await ext : ext ;
47- } else if ( language === "typst" ) {
48- console . log ( "Loading Typst language support" ) ;
49- try {
50- const { typst } = await import ( "codemirror-lang-typst" ) ;
51- languageExtension = typst ( ) ;
52- } catch ( e ) {
53- console . warn ( "Failed to load Typst language support:" , e ) ;
54- }
55- }
56-
5744 const extensions = [
5845 EditorState . readOnly . of ( true ) ,
5946 polyTheme ,
6047 lineNumbers ( ) ,
6148 syntaxHighlighting ( defaultHighlightStyle ) ,
62- languageExtension ,
49+ languageMap [ language ] ? languageMap [ language ] ( ) : [ ] ,
6350 ] ;
6451
6552 let div = document . createElement ( "div" ) ;
0 commit comments