首页 > 解决方案 > 在 Jupyter 笔记本中,如何获得 javascript 魔法单元的语法高亮显示?

问题描述

Jupyter Notebook 中的 Javascript 魔法单元

当我在本地笔记本中运行一个单元时,我看到了上面的内容。如何让 Jupyter 对这些单元格应用语法突出显示?

标签: jupyter-notebook

解决方案


以下代码适用于带有笔记本 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(); } }) ;
  });
});

推荐阅读