代码之家  ›  专栏  ›  技术社区  ›  Chris

如何使jupytersql突出显示的单元格可执行?

  •  0
  • Chris  · 技术社区  · 4 年前

    小猪背在回答下面。
    adding syntax highlighting to Jupyter notebook cell magic

    jupyter/custom/custom.js .

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

    这使得SQL语法突出显示为true,但是由于
    “用法错误:细胞魔法 %%sql 找不到。“。
    enter image description here

    0 回复  |  直到 4 年前
        1
  •  0
  •   JulioY    4 年前

    你得打电话 %load_ext sql %%sql 魔法细胞。

    enter image description here

    See ipython-sql reference