Parse token type and style string. :param token_name: str name of Pygments token. Example: "Token.String" :param style_object: pygments.style.Style instance to use as base :param style_dict: dict of token names and their styles, customized to this cli
(
token_name: str,
style_object: type[PygmentsStyle] | PygmentsStyle | dict[object, str] | str,
style_dict: dict[str, str],
)
| 91 | |
| 92 | |
| 93 | def parse_pygments_style( |
| 94 | token_name: str, |
| 95 | style_object: type[PygmentsStyle] | PygmentsStyle | dict[object, str] | str, |
| 96 | style_dict: dict[str, str], |
| 97 | ) -> tuple[Token, str]: |
| 98 | """Parse token type and style string. |
| 99 | |
| 100 | :param token_name: str name of Pygments token. Example: "Token.String" |
| 101 | :param style_object: pygments.style.Style instance to use as base |
| 102 | :param style_dict: dict of token names and their styles, customized to this cli |
| 103 | |
| 104 | """ |
| 105 | token_type = string_to_tokentype(token_name) |
| 106 | if isinstance(style_object, type) and issubclass(style_object, PygmentsStyle): |
| 107 | # When a Pygments Style class is passed, use its "styles" mapping. |
| 108 | other_token_type = string_to_tokentype(style_dict[token_name]) |
| 109 | style_class = cast(type[PygmentsStyle], style_object) |
| 110 | return token_type, style_class.styles[other_token_type] |
| 111 | elif isinstance(style_object, PygmentsStyle): |
| 112 | other_token_type = string_to_tokentype(style_dict[token_name]) |
| 113 | return token_type, style_object.styles[other_token_type] |
| 114 | else: |
| 115 | return token_type, style_dict[token_name] |
| 116 | |
| 117 | |
| 118 | def is_valid_pygments(name: str) -> bool: |
no outgoing calls
no test coverage detected