|
| SyntaxTheme | get_theme (cls, Union[str, SyntaxTheme] name) |
| |
|
None | __init__ (self, str code, Union[Lexer, str] lexer, *Union[str, SyntaxTheme] theme=DEFAULT_THEME, bool dedent=False, bool line_numbers=False, int start_line=1, Optional[Tuple[Optional[int], Optional[int]]] line_range=None, Optional[Set[int]] highlight_lines=None, Optional[int] code_width=None, int tab_size=4, bool word_wrap=False, Optional[str] background_color=None, bool indent_guides=False, PaddingDimensions padding=0) |
| |
| "Syntax" | from_path (cls, str path, str encoding="utf-8", Optional[Union[Lexer, str]] lexer=None, Union[str, SyntaxTheme] theme=DEFAULT_THEME, bool dedent=False, bool line_numbers=False, Optional[Tuple[int, int]] line_range=None, int start_line=1, Optional[Set[int]] highlight_lines=None, Optional[int] code_width=None, int tab_size=4, bool word_wrap=False, Optional[str] background_color=None, bool indent_guides=False, PaddingDimensions padding=0) |
| |
| str | guess_lexer (cls, str path, Optional[str] code=None) |
| |
| Optional[Lexer] | lexer (self) |
| |
| Text | highlight (self, str code, Optional[Tuple[Optional[int], Optional[int]]] line_range=None) |
| |
| None | stylize_range (self, StyleType style, SyntaxPosition start, SyntaxPosition end) |
| |
|
"Measurement" | __rich_measure__ (self, "Console" console, "ConsoleOptions" options) |
| |
|
RenderResult | __rich_console__ (self, Console console, ConsoleOptions options) |
| |
|
| Style | _get_base_style (self) |
| |
| Optional[Color] | _get_token_color (self, TokenType token_type) |
| |
|
Color | _get_line_numbers_color (self, float blend=0.3) |
| |
| int | _numbers_column_width (self) |
| |
| Tuple[Style, Style, Style] | _get_number_styles (self, Console console) |
| |
| Iterable[Segment] | _get_syntax (self, Console console, ConsoleOptions options) |
| |
| None | _apply_stylized_ranges (self, Text text) |
| |
| Tuple[bool, str] | _process_code (self, str code) |
| |
|
Dict[str, str] | _repr_mimebundle_ ("ConsoleRenderable" self, Sequence[str] include, Sequence[str] exclude, **Any kwargs) |
| |
Construct a Syntax object to render syntax highlighted code.
Args:
code (str): Code to highlight.
lexer (Lexer | str): Lexer to use (see https://pygments.org/docs/lexers/)
theme (str, optional): Color theme, aka Pygments style (see https://pygments.org/docs/styles/#getting-a-list-of-available-styles). Defaults to "monokai".
dedent (bool, optional): Enable stripping of initial whitespace. Defaults to False.
line_numbers (bool, optional): Enable rendering of line numbers. Defaults to False.
start_line (int, optional): Starting number for line numbers. Defaults to 1.
line_range (Tuple[int | None, int | None], optional): If given should be a tuple of the start and end line to render.
A value of None in the tuple indicates the range is open in that direction.
highlight_lines (Set[int]): A set of line numbers to highlight.
code_width: Width of code to render (not including line numbers), or ``None`` to use all available width.
tab_size (int, optional): Size of tabs. Defaults to 4.
word_wrap (bool, optional): Enable word wrapping.
background_color (str, optional): Optional background color, or None to use theme color. Defaults to None.
indent_guides (bool, optional): Show indent guides. Defaults to False.
padding (PaddingDimensions): Padding to apply around the syntax. Defaults to 0 (no padding).
| "Syntax" pip._vendor.rich.syntax.Syntax.from_path |
( |
|
cls, |
|
|
str |
path, |
|
|
str |
encoding = "utf-8", |
|
|
Optional[Union[Lexer, str]] |
lexer = None, |
|
|
Union[str, SyntaxTheme] |
theme = DEFAULT_THEME, |
|
|
bool |
dedent = False, |
|
|
bool |
line_numbers = False, |
|
|
Optional[Tuple[int, int]] |
line_range = None, |
|
|
int |
start_line = 1, |
|
|
Optional[Set[int]] |
highlight_lines = None, |
|
|
Optional[int] |
code_width = None, |
|
|
int |
tab_size = 4, |
|
|
bool |
word_wrap = False, |
|
|
Optional[str] |
background_color = None, |
|
|
bool |
indent_guides = False, |
|
|
PaddingDimensions |
padding = 0 |
|
) |
| |
Construct a Syntax object from a file.
Args:
path (str): Path to file to highlight.
encoding (str): Encoding of file.
lexer (str | Lexer, optional): Lexer to use. If None, lexer will be auto-detected from path/file content.
theme (str, optional): Color theme, aka Pygments style (see https://pygments.org/docs/styles/#getting-a-list-of-available-styles). Defaults to "emacs".
dedent (bool, optional): Enable stripping of initial whitespace. Defaults to True.
line_numbers (bool, optional): Enable rendering of line numbers. Defaults to False.
start_line (int, optional): Starting number for line numbers. Defaults to 1.
line_range (Tuple[int, int], optional): If given should be a tuple of the start and end line to render.
highlight_lines (Set[int]): A set of line numbers to highlight.
code_width: Width of code to render (not including line numbers), or ``None`` to use all available width.
tab_size (int, optional): Size of tabs. Defaults to 4.
word_wrap (bool, optional): Enable word wrapping of code.
background_color (str, optional): Optional background color, or None to use theme color. Defaults to None.
indent_guides (bool, optional): Show indent guides. Defaults to False.
padding (PaddingDimensions): Padding to apply around the syntax. Defaults to 0 (no padding).
Returns:
[Syntax]: A Syntax object that may be printed to the console
| str pip._vendor.rich.syntax.Syntax.guess_lexer |
( |
|
cls, |
|
|
str |
path, |
|
|
Optional[str] |
code = None |
|
) |
| |
Guess the alias of the Pygments lexer to use based on a path and an optional string of code.
If code is supplied, it will use a combination of the code and the filename to determine the
best lexer to use. For example, if the file is ``index.html`` and the file contains Django
templating syntax, then "html+django" will be returned. If the file is ``index.html``, and no
templating language is used, the "html" lexer will be used. If no string of code
is supplied, the lexer will be chosen based on the file extension..
Args:
path (AnyStr): The path to the file containing the code you wish to know the lexer for.
code (str, optional): Optional string of code that will be used as a fallback if no lexer
is found for the supplied path.
Returns:
str: The name of the Pygments lexer that best matches the supplied path/code.
| None pip._vendor.rich.syntax.Syntax.stylize_range |
( |
|
self, |
|
|
StyleType |
style, |
|
|
SyntaxPosition |
start, |
|
|
SyntaxPosition
|
end |
|
) |
| |
Adds a custom style on a part of the code, that will be applied to the syntax display when it's rendered.
Line numbers are 1-based, while column indexes are 0-based.
Args:
style (StyleType): The style to apply.
start (Tuple[int, int]): The start of the range, in the form `[line number, column index]`.
end (Tuple[int, int]): The end of the range, in the form `[line number, column index]`.