diff options
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r-- | pygments/formatters/html.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index d9e68a99..ee53f132 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -878,14 +878,12 @@ class HtmlFormatter(Formatter): # for all but the last line for part in parts[:-1]: if line: - if lspan != cspan: - # If part is empty (i.e. it was a newline), just close - if part: - line.extend(((lspan and '</span>'), cspan, part, - (cspan and '</span>'), lsep)) - else: - line.extend(((lspan and '</span>'), lsep)) - else: # both are the same + # Also check for part being non-empty, so we avoid creating + # empty <span> tags + if lspan != cspan and part: + line.extend(((lspan and '</span>'), cspan, part, + (cspan and '</span>'), lsep)) + else: # both are the same, or the current part was empty line.extend((part, (lspan and '</span>'), lsep)) yield 1, ''.join(line) line = [] |