@@ -16,13 +16,12 @@ import from "@tabler/icons-react" {
1616 IconCheck
1717}
1818
19- # Monaco Editor - React wrapper
20- import from "@monaco -editor /react " { Editor }
19+ # CodeMirror syntax highlighting for Jac
20+ import from "..utils /syntax_highlighting " { getJacExtensions }
21+ import from "@codemirror /view " { EditorView }
22+ import from "@codemirror /state " { EditorState }
2123
22- # Syntax highlighting utilities
23- import from "..utils /syntax_highlighting " { highlightJacCode }
24-
25- # Jac syntax highlighting CSS
24+ # Jac syntax highlighting CSS (kept for highlight.js bash/shell overrides)
2625import "..styles /jacSyntax .css ";
2726
2827
@@ -101,29 +100,35 @@ def:pub CodeBlock(language: str, code: str, children: any = null) -> any {
101100}
102101
103102
104- """ Lightweight Jac code block with tokenizer-based syntax highlighting ."""
103+ """ Read-only Jac code block using CodeMirror 6 ."""
105104def :pub JacCodeBlock (code : str ) -> any {
106- console.log(" === JacCodeBlock rendered ===" );
107- console.log(" Code to highlight:" , code);
108-
109105 has copied : bool = false ;
110- has highlightedCode : str = code ;
106+ editorRef = useRef(None );
107+ viewRef = useRef(None );
111108
112109 def handleCopy () -> None {
113110 navigator.clipboard.writeText(code);
114111 copied = true;
115112 setTimeout(lambda { copied = false; }, 2000 );
116113 }
117114
118- # Highlight code on mount and when code changes
115+ # Create / destroy the CodeMirror EditorView when code changes
119116 useEffect(lambda {
120- console.log(" === useEffect triggered for highlighting ===" );
121- console.log(" Calling highlightJacCode with:" , code);
122- highlightJacCode(code).then(lambda result: any {
123- console.log(" === Highlighting complete ===" );
124- console.log(" Result:" , result);
125- highlightedCode = result;
126- });
117+ if viewRef.current {
118+ viewRef.current.destroy();
119+ viewRef.current = None ;
120+ }
121+ if editorRef.current {
122+ state = EditorState.create({
123+ " doc" : code,
124+ " extensions" : getJacExtensions()
125+ });
126+ viewRef.current = Reflect.construct(EditorView, [{
127+ " state" : state,
128+ " parent" : editorRef.current
129+ }]);
130+ }
131+ return lambda { if viewRef.current { viewRef.current.destroy(); viewRef.current = None ; } };
127132 }, [code]);
128133
129134 copyLabel = " Copy code" ;
@@ -167,21 +172,7 @@ def:pub JacCodeBlock(code: str) -> any {
167172 </Group >
168173
169174 <Box px = " md" py = " sm" style = { {" overflowX" : " auto" }} >
170- <pre
171- className = " jac-code"
172- style = { {
173- " margin" : " 0" ,
174- " padding" : " 0" ,
175- " fontSize" : " 13px" ,
176- " lineHeight" : " 1.5" ,
177- " fontFamily" : " Monaco, Menlo, Ubuntu Mono, monospace" ,
178- " whiteSpace" : " pre-wrap" ,
179- " wordBreak" : " break-word" ,
180- " color" : " #d4d4d4" ,
181- " background" : " transparent"
182- }}
183- dangerouslySetInnerHTML = { { " __html" : highlightedCode }}
184- />
175+ <div ref = { editorRef} className = " jac-codemirror-wrapper" />
185176 </Box >
186177 </Paper >
187178 </Box >;
0 commit comments