When I run a cell in my local notebook I see the above. How do I get Jupyter to apply syntax highlighting to these cells?
2 Answers
The following code works for SQL when placed in ~/.jupyter/custom/custom.js with notebook 5.x:
require(['notebook/js/codecell'], function(codecell) {
codecell.CodeCell.options_default.highlight_modes['magic_text/x-mssql'] = {'reg':[/^%%sql/]} ;
Jupyter.notebook.events.one('kernel_ready.Kernel', function(){
Jupyter.notebook.get_cells().map(function(cell){
if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;
});
});
1 Comment
Ian Danforth
I've removed the SQL specific stuff as an edit, and it works! Apparently JS highlighting is available "out of the box."
JavaScript version:
%%js
require(['notebook/js/codecell'], (codecell) => {
codecell.CodeCell.options_default.highlight_modes.magic_javascript =
{reg: [/^%%(?:js|javascript|script node)/]}
Jupyter.notebook.events.one('kernel_ready.Kernel', () => {
Jupyter.notebook.get_cells().map((cell) => {
if (cell.cell_type == 'code'){
cell.auto_highlight()
}})
})
})
