From 6765ec070fd73ba7bfa5ea464d4e720e61599f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20G=2E=20Chajdas?= Date: Sun, 11 Dec 2022 15:30:01 +0100 Subject: Simplify the condition. --- pygments/formatters/html.py | 14 ++++++-------- 1 file 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 ''), cspan, part, - (cspan and ''), lsep)) - else: - line.extend(((lspan and ''), lsep)) - else: # both are the same + # Also check for part being non-empty, so we avoid creating + # empty tags + if lspan != cspan and part: + line.extend(((lspan and ''), cspan, part, + (cspan and ''), lsep)) + else: # both are the same, or the current part was empty line.extend((part, (lspan and ''), lsep)) yield 1, ''.join(line) line = [] -- cgit v1.2.1