adding syntax highlighting to Jupyter notebook cell magic

后端 未结 2 1651
半阙折子戏
半阙折子戏 2020-12-31 16:44

I\'m trying to figure out how to activate CodeMirror syntax highlighting for a CodeMirror-supported language (cypher) within a cell for a custom Jupyter cell magic (%%

2条回答
  •  清酒与你
    2020-12-31 17:13

    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(); } }) ;
      });
    });
    

    Credit goes to Thomas K for this info!

提交回复
热议问题