Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding syntax highlighting for other languages (suggested fix inside) #539

Open
izaid opened this issue May 10, 2017 · 3 comments
Open

Adding syntax highlighting for other languages (suggested fix inside) #539

izaid opened this issue May 10, 2017 · 3 comments

Comments

@izaid
Copy link

izaid commented May 10, 2017

So, I know that instead of magics, IJulia suggests custom string literals -- i.e., #408. What would be really great is if we could support syntax highlighting of other languages in these strings. The justification for this is that multilanguage notebooks are a somewhat popular thing. I, for example, would like to mix Julia and JavaScript every now and then. And multilanguages do work in IJulia, it's just that the highlighting isn't there.

However, this could be fixed as per something like this suggestion -- http://stackoverflow.com/questions/43641362/adding-syntax-highlighting-to-jupyter-notebook-cell-magic/43644349. The following modification of that actually gives JavaScript syntax highlighting to JavaScript string literals within IJulia notebooks:

javascript"""
require(['notebook/js/codecell'], function(codecell) {
codecell.CodeCell.options_default.highlight_modes['text/javascript'] = {'reg':[/^javascript/]} ;
  Jupyter.notebook.events.one('kernel_ready.Kernel', function(){
  Jupyter.notebook.get_cells().map(function(cell){
      if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;
  });
});
"""

Would it be possible to add something like this to IJulia itself? I'd make the PR if people were happy and it was clear where to put this in the IJulia source.

@stevengj
Copy link
Member

Wouldn't this give JavaScript syntax highlighting to the entire cell even if only the part of the cell is a JavaScript string literal?

@izaid
Copy link
Author

izaid commented May 11, 2017

Yeah, it does. I expect we could figure out a way to do highlighting of the string contents only. If that was the case, is this of interest?

@JobJob
Copy link
Contributor

JobJob commented May 11, 2017

I think it only highlights js syntax for cells that begin with javascript""", I think that's fine, I like it. Any ideas on where we could run it?

It does work if you put just the following in ~/.jupyter/nbconfig/custom/custom.js

require(["notebook/js/codecell"], function(codecell) {
    codecell.CodeCell.options_default.highlight_modes["text/javascript"] = {"reg":[/^javascript/]}
})

But making it Julia specific would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants