在Jupyter笔记本中,如何获取JavaScript魔术单元的语法突出显示?

时间:2019-10-20 15:39:37

标签: jupyter-notebook

Javascript Magic Cell in Jupyter Notebook

当我在本地笔记本中运行单元格时,会看到以上内容。如何让Jupyter将语法突出显示应用于这些单元格?

2 个答案:

答案 0 :(得分:1)

以下代码在笔记本5.x中放置在〜/ .jupyter / custom / custom.js中时可用于SQL:

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 :(得分:0)

JavaScript版本:

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