qtconsole icon indicating copy to clipboard operation
qtconsole copied to clipboard

Syntax highlighting stops working when changing in_prompt

Open pag opened this issue 6 years ago • 3 comments

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.

pag avatar Dec 24 '18 18:12 pag

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.

wmvanvliet avatar Dec 24 '18 21:12 wmvanvliet

do you know any workaround ?

phineas-pta avatar May 31 '19 09:05 phineas-pta

don't change the prompt :)

wmvanvliet avatar May 31 '19 16:05 wmvanvliet