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

Typing zero in front of numbers breaks code display and syntax highlighting #887

Closed
Firionus opened this issue Nov 14, 2019 · 5 comments
Closed

Comments

@Firionus
Copy link

Minimal example

  • create new Julia Jupyter Notebook
  • wait for Kernel to load (bug only showed when Kernel loaded)
  • type "01" in first cell -> the cell shows "0" (first two errors in console)
  • hit Shift+Enter -> outputs "1" (next to errors in console)
  • copy the "0" from the first cell into the second one (even though text from first cell is not visibly marked when dragging mouse over it, just move like it would and hit Ctrl+C) -> nothing appears in second cell when pasting
  • hit Shift+Enter -> second cell outputs "1"
  • Save the notebook
  • File => Close and Halt
  • Reopen Notebook -> Both cells show "01" in black. Syntax Highlighting does not work in these or any other new cells, no matter the content.

This is the console dump from Chrome:
IJuliaZeroBugChrome.log

Breaking Strings

  • 01
  • 02
  • 06
  • 00
  • -01
  • +01
  • .01
  • .02
  • \01
  • (01
  • ?01
  • =01
  • 0,01 (no 1)
  • 01. (one appears after hitting ".". Backspace needs to be hit two times to remove both dot and one)
  • 00.01 (analogous with dot)
  • 00a (only first zero appears)

Non-breaking Strings

  • a01
  • z04
  • _01
  • 0.2
  • 0.0
  • 0.01
  • '01
  • "01
  • 0"1
  • 0a
  • 0'

Python Notebooks

Nothing breaks in a Python Notebook.

Versions

julia> versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, sandybridge)
>jupyter --version
jupyter core     : 4.6.1
jupyter-notebook : 6.0.2
qtconsole        : 4.5.5
ipython          : 7.9.0
ipykernel        : 5.1.3
jupyter client   : 5.3.4
jupyter lab      : not installed
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 4.4.0
traitlets        : 4.3.3

[7073ff75] IJulia v1.20.2

Tested with Firefox 71.0b9 and Chrome 78.0.3904.97

The problem appeared after I did a complete update-run of my Python install (lots of things) and Julia (1.1.1 -> 1.2.0 complete reinstall), so it's hard to trace the origin.

Notebook from minimal example

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "@webio": {
   "lastCommId": null,
   "lastKernelId": null
  },
  "kernelspec": {
   "display_name": "Julia 1.2.0",
   "language": "julia",
   "name": "julia-1.2"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
@stevengj
Copy link
Member

stevengj commented Nov 14, 2019

Syntax highlighting in Jupyter is done by CodeMirror, not the IJulia package (which just provides the backend kernel), so you should report the problem there.

@alanedelman
Copy link

i'm experiencing this problem with Julia 1.4 and Julia 1.5-rc1 on my mac
anything i can try?

@stevengj
Copy link
Member

The problem was fixed in CodeMirror, and Jupyter was recently updated to use a more recent CodeMirror release, which should fix the bug: jupyter/notebook#5469

However, you may have to wait until Jupyter 6.1.0 is released and incorporated in to the Conda package; otherwise, the only way to get it seems to be to use pip to install from source.

There might be a way to upgrade codemirror manually somehow, though?

@Firionus
Copy link
Author

There might be a way to upgrade codemirror manually somehow, though?

Probably not a good solution, but I just replaced <jupyter-path>/notebook/static/components/codemirror/mode/julia/julia.js with the version from the Github repo:
https://github.com/codemirror/CodeMirror/blob/master/mode/julia/julia.js

To find <jupyter-path> I used pip3 show jupyterlab (only when installed via pip. might just be pip on your system).

@stevengj
Copy link
Member

stevengj commented Jul 24, 2020

We used to have to update codemirror ourselves, which we actually used to do in early versions.

In particular, if you are using the Conda installation of Jupyter (the default on Mac and Windows) you could do something like:

using Conda
highlighter = joinpath(readchomp(Conda._set_conda_env(`$(joinpath(Conda.PYTHONDIR, "python")) -c "import site; print(site.getsitepackages()[0])"`)), "notebook", "static", "components", "codemirror", "mode", "julia", "julia.js")
if isfile(highlighter)
    cm_commit = "772d09e697612889ec5dbed2cc058e754232c29d" # v5.56.0
    highlighter_url = "https://raw.githubusercontent.com/codemirror/CodeMirror/" * cm_commit * "/mode/julia/julia.js"
    download(highlighter_url, highlighter)
end

Update: this fixes the problem for me.

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