Skip to content

Is there a way to have q syntax highlighting in cells starting with %%q in jupyter notebook? #149

@flcong

Description

@flcong

When using PyQ with python in jupyter notebook, all cells use syntax highlighting of Python by default. This makes q code written in cells starting with %%q very confusing (suppose you use ' somewhere, and all code following it is highlighted as string in python). Hence, I wonder if someone knows some way to use q syntax highlighting in cells starting with %%q.

I find a similar question on stackoverflow. There is an answer about SQL. They say adding the following code in ~/.jupyter/custom/custom.js to use SQL syntax highlighting in cells starting with %%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(); } }) ;
  });
});

Yet, I am not sure how to modify the code in the answer so it recognizes q, particularly what the highlight_modes should be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions