diff --git a/rich/syntax.py b/rich/syntax.py index 7dd5922a3..759351907 100644 --- a/rich/syntax.py +++ b/rich/syntax.py @@ -351,6 +351,11 @@ def _get_token_color(self, token_type: TokenType) -> Optional[Color]: @property def lexer(self) -> Optional[Lexer]: + """The lexer for this syntax, or None if no lexer was found. + + Tries to find the lexer by name if a string was passed to the constructor. + """ + if isinstance(self._lexer, Lexer): return self._lexer try: