@@ -38,10 +38,17 @@ export let defaultExecutor: CodeExecutor = {
3838export class CodeBlock {
3939 code : string ;
4040 language : string ;
41+ detectLanguage : boolean ;
4142
42- constructor ( ) {
43+ constructor ( language ?: string ) {
4344 this . code = "" ;
4445 this . language = "" ;
46+ this . detectLanguage = true ;
47+
48+ if ( language ) {
49+ this . language = language ;
50+ this . detectLanguage = false ;
51+ }
4552 }
4653
4754 childrenView ( ) {
@@ -70,17 +77,17 @@ export class CodeBlock {
7077
7178 static initialize ( workbench : Workbench ) {
7279 workbench . commands . registerCommand ( {
73- id : "make-code-snippet " ,
74- title : "Make Code Snippet " ,
80+ id : "make-code-block " ,
81+ title : "Make Code Block " ,
7582 when : ( ctx : Context ) => {
7683 if ( ! ctx . node ) return false ;
7784 if ( ctx . node . raw . Rel === "Fields" ) return false ;
7885 if ( ctx . node . parent && ctx . node . parent . hasComponent ( Document ) )
7986 return false ;
8087 return true ;
8188 } ,
82- action : ( ctx : Context ) => {
83- const com = new CodeBlock ( ) ;
89+ action : ( ctx : Context , language ?: string ) => {
90+ const com = new CodeBlock ( language ) ;
8491 if ( ctx ?. node ) {
8592 ctx . node . addComponent ( com ) ;
8693 ctx . node . changed ( ) ;
@@ -110,9 +117,12 @@ const CodeEditor = {
110117 editor . textContent = editor . textContent ;
111118 //@ts -ignore
112119 window . hljs . highlightBlock ( editor ) ;
113- snippet . language =
120+
121+ if ( snippet . detectLanguage ) {
114122 //@ts -ignore
115- window . hljs . highlightAuto ( editor . textContent ) . language || "" ;
123+ snippet . language = window . hljs . highlightAuto ( editor . textContent ) . language || "" ;
124+ }
125+
116126 } ) ;
117127 dom . jarEditor . updateCode ( snippet . code ) ;
118128 dom . jarEditor . onUpdate ( ( code ) => {
0 commit comments