qtconsole
qtconsole copied to clipboard
Syntax highlighting stops working when changing in_prompt
qtconsole 4.4.3, python 3.7.1 (via anaconda 2018.12 / 4.5.12), Windows 10.
Steps to reproduce: just change JupyterWidget.in_prompt
(in e.g. jupyter_qtconsole_config.py) to anything else, for example 'Blah [<span class="in-prompt-number">%i</span>]: '
. Now code is not highlighted.
I think the culprit is that frontend.other_output_prefix
is giving me '[remote] '
at the point where it's used in FrontendHighlighter._ipy_prompt_re
.
I believe that this worked fine under qtconsole 4.4.0.
Your assessment is almost correct. The problem is indeed the logic for determining whether a cell contains input (which should be syntax highlighted) or output (which should not be). This is currently done with a regex:
https://github.com/jupyter/qtconsole/blob/master/qtconsole/frontend_widget.py#L39
The frontend.other_output_prefix
is present when code is received from another connected frontend (e.g. a text editor), but since it is an optional part of the pattern, that should not be the main problem.
The main problem is that the regex assumes that the in-prompt is the default and cannot deal with a custom prompt at all. The solution is to not rely on a regex to distinguish input/output cells, but rather properly "tag" cells when they are created, avoiding this whole pattern matching business.
do you know any workaround ?
don't change the prompt :)