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

Notebook: Syntax highlighting not working in Safari #168

Closed
apleonhardt opened this issue Apr 23, 2014 · 21 comments
Closed

Notebook: Syntax highlighting not working in Safari #168

apleonhardt opened this issue Apr 23, 2014 · 21 comments

Comments

@apleonhardt
Copy link

This may be a minor issue but is probably worth reporting: For some reason, Julia syntax highlighting doesn't work for IJulia notebooks in Safari on Mac OS X 10.9. I've tried to pin down the issue:

  • Highlighting works in Python mode.
  • Highlighting works in Chrome (calling up the very same IPython instance).
  • No JS errors are thrown when IJulia boots up.

I'm not very knowledgeable when it comes to JS. A couple of amateurish observations: The language setting for all cells is correctly set to Julia. Loading up the notebook in Julia mode does throw up loads of CSS warnings whereas loading a Python notebook doesn't. Maybe it's something trivial. Can any Mac user confirm this observation?

@apleonhardt
Copy link
Author

Might belong to #17.

@stevengj
Copy link
Member

@malmaud, any ideas?

@lucasb-eyer
Copy link

  • Same for me in Firefox 28.0 on Arch Linux.
  • Highlighting doesn't work for loaded existing cells in Firefox.
  • Highlighting does work in Chrome.
  • Highlighting does work in newly created cells.
  • Highlighting does work when changing the cell type e.g. to markdown and then back to code.
  • I think it started failing when I updated my IPython from 1.2.? to 2.0.

It looks like some "lazy" highlighting upon loading the notebook is being too lazy (aka never called) in Firefox and Safari but not in Chrome?

@padawanphysicist
Copy link

  • Same problem in Firefox 29.0-1 on Arch Linux. Only highlights new cells.
  • Highlight working in Opera and Chrome

@stevengj
Copy link
Member

@Carreau, did something change in IPython 2.0 about how syntax highlighting is applied to cells when they are loaded?

@Carreau
Copy link
Contributor

Carreau commented May 12, 2014

Nop nothing should have changed.

Can you try pasting this in the JS console ?

    CodeMirror.requireMode('julia', function(){
        cells = IPython.notebook.get_cells();
        for(var i in cells){
            c = cells[i];
            if (c.cell_type === 'code'){
                c.auto_highlight()
            }
        }
    })

If it works we might want to wrap this also in the notebook_loaded.NotebookApp event.

@apleonhardt
Copy link
Author

It doesn't. A manual call to a cell's auto_highlight() doesn't either.

This, on the other hand, works:

cells = IPython.notebook.get_cells();
cells[0].code_mirror.setOption("mode", "julia");

The architecture is a bit puzzling, so I can't tell if it's an issue with CodeMirror, IPython or IJulia. It seems similar to IHaskell/IHaskell#71, though! Any ideas?

@Carreau
Copy link
Contributor

Carreau commented May 12, 2014

Weird.
What does cells[0].code_mirror.getOption("mode") says ?
Cause I can fix it in customjs, but it will probably double the time of loading notebook has it will highlight things twice.

@malmaud
Copy link
Contributor

malmaud commented May 12, 2014

@stevengj Hmm, it still works for me. I have no special insight on what's going wrong.

@Carreau
Copy link
Contributor

Carreau commented May 12, 2014

That's probably a race condition between codemirror requiring the "julia" . So Codemirror try to parse in julia mode but as it is not defined, or initialized yet the highlighting default to 'plain/text'( even if the option is set to 'julia') for newly created cell, julia mode is defined so it works.

auto_highlight() look at the mode, see julia, so does nothing (otherwise all the highlighting is re-done, which ~ double the loading time of notebook).

It should not happend has the autohilight is triggered only once julia mode is loaded, but it might come from the fact that the actual highlighting of codemirror is done in a pseudo-background thread using callbacks .

@apleonhardt
Copy link
Author

@Carreau cell.code_mirror.getOption("mode") always returns julia, regardless of highlighting status. The race condition idea sounds reasonable. It's a minor annoyance because toggling the cell type twice restores proper highlighting. Seems sufficiently widespread, though, and doesn't give an ideal first impression...

@staticfloat
Copy link
Sponsor Member

I run into a problem that is very similar, but I'm not certain it's the same. When I open an existing IJulia notebook that has a lot of "stuff" (plots, code cells, etc....), sometimes syntax highlighting doesn't work at all, (even though computation still works) and closing the window and reopening, or normal refreshing does not fix the issue. However, force-refreshing, (CMD-SHIFT-R in Chrome on OSX) always fixes the issue, so I think it might have something to do with files getting fetched in a weird order and not being pulled from Chrome's cache properly? The issue is perplexing, and if this is not the same as what's being talked about here, I can go open a new issue, but it's hard to know since my problem is intermittent.

@lendle
Copy link

lendle commented Aug 26, 2014

I am having what I think is the same issue. I found that #201 fixes this for me.

(For reasons I don't understand, Pkg.build("IJulia") didn't do anything after checking out the master branch. I made a whitespace-only change to custom.js, and after that Pkg.build("IJulia") updated custom.js in my IPython profile and syntax highlighting was fixed.)

@lendle
Copy link

lendle commented Aug 26, 2014

Oops, please ignore my previous comment.

Looks like #201 was merged a while ago, well before the most recent tagged version of IJulia. After removing and reinstalling IJulia, this issue is not actually fixed for me. I think something screwy is going on in my .julia directory.

@null-a
Copy link

null-a commented Dec 17, 2014

I think I'm seeing much the same thing. If I open an existing notebook in Firefox there's no syntax highlighting for Julia code.

Calling cell.code_mirror.setOption("mode", "julia") for all code cells (as suggested by @apleonhardt) from the app_initialized.NotebookApp event (in custom.js) fixes things. I've no idea how much of a hack that is though.

I see something similar in Chrome, though there it's intermittent. Sometimes existing notebooks open with syntax highlighting, other times not.

I'm on julia 0.3.3, IJulia, 0.1.16, ipython 2.3.0, Firefox 34.0.5, OS X 10.9.5.

@eldargab
Copy link

One way to workaround is to add the following to custom.js

CodeMirror.requireMode('julia', function(){
  IPython.CodeCell.options_default.cm_config.mode = "julia"
})

This will not change the mode of already created cells (in old notebooks), but will set the right mode for new ones.

The above works for ipython 2.3

@Carreau
Copy link
Contributor

Carreau commented Dec 29, 2014

That's basically what this is doing, but there seem to be some timing issues.

So you should not need to add that manually to your custom.js it should be added to it by IJulia when you Pkg.build it.

With next version of IPython it should be taken care of by IPython itself.

@eldargab
Copy link

Ah, indeed, seems that I overwrote custom.js after install.

@stevengj
Copy link
Member

Is there a change that is needed to our custom.js for IPython 1.x and 2.x?

@zmughal
Copy link

zmughal commented Aug 4, 2015

This may have been fixed in IPython 3.2. See the issue at EntropyOrg/p5-Devel-IPerl#40 for more details.

@stevengj
Copy link
Member

stevengj commented Aug 4, 2015

@zmughal, that's good to hear. (The latest IJulia master dropped support for IPython 2.x.)

This issue was closed.
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