Skip to content

Commit 8e3b862

Browse files
authored
Fix python code execution for ImJoy code blocks
For some reason the code highlighter do not provide the `data-lang` attribute any longer, this is a quick fix to make sure we can run js and python properly.
1 parent f475fb5 commit 8e3b862

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

assets/js/imjoy-app.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@
110110
if (config.type === 'window') {
111111
cfg.defaults = {}
112112
}
113-
113+
if (!config.lang) {
114+
if(cfg.type.includes("python")){
115+
config.lang = "python"
116+
}
117+
else if(cfg.type.includes("javascript")){
118+
config.lang = "javascript"
119+
}
120+
else{
121+
console.error('"lang" is not specified, please make sure decorate the code block with the name of the language.')
122+
}
123+
}
114124
if (config.lang !== 'html')
115125
src = `<config lang="json">\n${JSON.stringify(cfg, null, 1)}\n</config>\n<script lang="${config.lang}">\n${src}<\/script>`;
116126
else
@@ -312,6 +322,7 @@
312322
preElm.pluginConfig.id = id;
313323

314324
preElm.pluginConfig.namespace = id;
325+
// for some reason, the data-lang attribute disappeared in the newer version
315326
preElm.pluginConfig.lang = preElm.getAttribute('data-lang');
316327

317328
const outputFullscreenElm = preElm.querySelector(".fullscreen-button");
@@ -694,4 +705,4 @@
694705
initializeRunButtons();
695706
});
696707

697-
})();
708+
})();

0 commit comments

Comments
 (0)