empty <span></span> at the begining of the highlight since 2.1.1

Issue #1254 wontfix
André Felipe Dias
created an issue

Since v.2.1.1, the hightlight output starts with an empty span tag.

Steps to reproduce:

#!/usr/bin/python3

from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

def pygmentize(code, language, **kwargs):
    lexer = get_lexer_by_name(language)
    formatter = HtmlFormatter(**kwargs)
    return highlight(code, lexer, formatter)

code = 'print("hello world")'
print(pygmentize(code, 'python'))

code = '# comment'
print(pygmentize(code, 'bash'))

at Pygments 2.1 and before, the output is:

<div class="highlight"><pre><span class="k">print</span><span class="p">(</span><span class="s2">&quot;hello world&quot;</span><span class="p">)</span>
</pre></div>

<div class="highlight"><pre><span class="c1"># comment</span>
</pre></div>

Since Pygments 2.1.1, the output is:

<div class="highlight"><pre><span></span><span class="k">print</span><span class="p">(</span><span class="s2">&quot;hello world&quot;</span><span class="p">)</span>
</pre></div>

<div class="highlight"><pre><span></span><span class="c1"># comment</span>
</pre></div>

Note the empty span tag just after <pre>. It doesn't look right.

Comments (3)

  1. Log in to comment