Skip to content

Commit

Permalink
Don't color leading or trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Aug 3, 2023
1 parent 78384cb commit 19fceff
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 47 deletions.
12 changes: 9 additions & 3 deletions specialist.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _audit_imports(event: str, args: "typing.Sequence[object]") -> None:
import itertools
import opcode
import os
import re
import runpy
import shlex
import sysconfig
Expand All @@ -44,6 +45,7 @@ def _audit_imports(event: str, args: "typing.Sequence[object]") -> None:
import typing
import webbrowser

_RE_WHITESPACE = re.compile(r"(\s*\n\s*)")
_FIRST_POSTION = (1, 0)
_LAST_POSITION = (sys.maxsize, 0)
_CACHE_FORMAT = frozenset(opcode._cache_format) # type: ignore [attr-defined] # pylint: disable = protected-access
Expand Down Expand Up @@ -119,9 +121,13 @@ def add(self, source: str, stats: "_Stats") -> None:
color = self._color(stats)
attribute = "color" if self._dark else "background-color"
source = html.escape(source)
if color != "#ffffff":
source = f"<span style='{attribute}:{color}'>{source}</span>"
self._parts.append(source)
if color == "#ffffff":
self._parts.append(source)
else:
for part in filter(None, _RE_WHITESPACE.split(source)):
if _RE_WHITESPACE.fullmatch(part) is None:
part = f"<span style='{attribute}:{color}'>{part}</span>"
self._parts.append(part)

def emit(self) -> str:
"""Emit the HTML."""
Expand Down
6 changes: 3 additions & 3 deletions test-data/output-blue/output-0-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-blue/output-1-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-blue/output-2-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-blue/output-3-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-blue/output-4-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test-data/output-dark-blue/output-0-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-dark-blue/output-1-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-dark-blue/output-2-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-dark-blue/output-3-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test-data/output-dark-blue/output-4-3-12.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 19fceff

Please sign in to comment.