Skip to content

Commit

Permalink
Change rich markdown theme/colors
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Sep 22, 2022
1 parent 2482270 commit 865748a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ansiblelint/color.py
Expand Up @@ -5,9 +5,20 @@

import rich
from rich.console import Console
from rich.default_styles import DEFAULT_STYLES
from rich.style import Style
from rich.syntax import Syntax
from rich.theme import Theme

DEFAULT_STYLES.update(
{
# "code": Style(color="bright_black", bgcolor="red"),
"markdown.code": Style(color="bright_black"),
"markdown.code_block": Style(dim=True, color="cyan"),
}
)


_theme = Theme(
{
"info": "cyan",
Expand Down Expand Up @@ -44,3 +55,18 @@ def reconfigure(new_options: dict[str, Any]) -> None:
def render_yaml(text: str) -> Syntax:
"""Colorize YAMl for nice display."""
return Syntax(text, "yaml", theme="ansi_dark")


# pylint: disable=redefined-outer-name,unused-argument
def _rich_heading_custom_rich_console(
self: rich.markdown.Heading,
console: rich.console.Console,
options: rich.console.ConsoleOptions,
) -> rich.console.RenderResult:
"""Override for rich console heading."""
yield f"[bright_white]{self.level * '#'} {self.text}[/]"


# Monkey-patch rich to alter its rendering of headings
# https://github.com/python/mypy/issues/2427
rich.markdown.Heading.__rich_console__ = _rich_heading_custom_rich_console # type: ignore
2 changes: 2 additions & 0 deletions src/ansiblelint/rules/jinja.py
Expand Up @@ -279,6 +279,8 @@ def uncook(value: str, implicit: bool = False) -> str:

except jinja2.exceptions.TemplateSyntaxError as exc:
return "", str(exc.message), "invalid"
# https://github.com/PyCQA/pylint/issues/7433 - py311 only
# pylint: disable=I1101
except (NotImplementedError, black.parsing.InvalidInput) as exc:
# black is not able to recognize all valid jinja2 templates, so we
# just ignore InvalidInput errors.
Expand Down

0 comments on commit 865748a

Please sign in to comment.