diff --git a/src/ansiblelint/color.py b/src/ansiblelint/color.py index 053dd28e31a..a773d14d506 100644 --- a/src/ansiblelint/color.py +++ b/src/ansiblelint/color.py @@ -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", @@ -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 diff --git a/src/ansiblelint/rules/jinja.py b/src/ansiblelint/rules/jinja.py index df416083029..a7ccbce452d 100644 --- a/src/ansiblelint/rules/jinja.py +++ b/src/ansiblelint/rules/jinja.py @@ -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.