(Original issue 1379 created by hroncok on 2017-09-22T10:25:28.507075+00:00)
I've recently find out that the space after prompt is styled inconsistently. See the examples.
$ pip install pygments
Collecting pygments
Using cached Pygments-2.2.0-py2.py3-none-any.whl
Installing collected packages: pygments
Successfully installed pygments-2.2.0
Python 3.6.2 (default, Aug 11 2017, 11:59:59)
[GCC 7.1.1 20170622 (Red Hat 7.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygments
>>> import pygments.lexers
>>> import pygments.formatters.html
>>> pygments_formatter = pygments.formatters.html.HtmlFormatter()
>>>
>>> def highlight(code, lang):
... lexer = pygments.lexers.get_lexer_by_name(lang)
... return pygments.highlight(code, lexer, pygments_formatter).strip()
...
>>> highlight('(venv) $ foo', 'console')
'<div class="highlight"><pre><span></span><span class="gp">(venv) $</span> foo\n</pre></div>'
>>>
>>>
>>> highlight('>>> import pygments', 'pycon')
'<div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pygments</span>\n</pre></div>'
>>>
>>>
>>> highlight('>>> with foo:\n... bar()', 'pycon')
'<div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="n">foo</span><span class="p">:</span>\n<span class="gp">... </span> <span class="n">bar</span><span class="p">()</span>\n</pre></div>'
Important parts:
The console lexer puts the space after the prompt span:
<span class="gp">(venv) $</span> foo
The pycon lexer puts the first space in the prompt span:
<span class="gp">>>> </span>
<span class="gp">... </span>
I find this behavior inconsistent an potentially problematic. In my opinion, the first space is part of the prompt and the pycon lexer is right, whereas the console lexer has a bug.
We had to incorporate a workaround in order to be able to style the prompt including the first space:
def style_space_after_prompt(html):
return re.sub(r'<span class="gp">([^<]*[^<\s])</span>(\s)',
r'<span class="gp">\1\2</span>',
html)
I wonder what do you think: is the first space supposed to be in the prompt span? Or does it deserve its own class?
Thanks
(Original issue 1379 created by hroncok on 2017-09-22T10:25:28.507075+00:00)
I've recently find out that the space after prompt is styled inconsistently. See the examples.
Important parts:
The console lexer puts the space after the prompt span:
The pycon lexer puts the first space in the prompt span:
I find this behavior inconsistent an potentially problematic. In my opinion, the first space is part of the prompt and the pycon lexer is right, whereas the console lexer has a bug.
We had to incorporate a workaround in order to be able to style the prompt including the first space:
I wonder what do you think: is the first space supposed to be in the prompt span? Or does it deserve its own class?
Thanks