Skip to content

rs_rich.syntax

Generated from the type stubs by scripts/gen_python_api.py; do not edit.

rich.syntax: Syntax, plus the port's code-highlighter choice.

Syntax(..., highlighter="syntect") (or "lumis" in a lumis build) picks the engine by name; code_highlighters() lists the names and code_themes(name) an engine's themes. Rich highlights with Pygments, so token colours differ from Rich's (see docs/python/syntax.md).

DEFAULT_THEME module-attribute

DEFAULT_THEME = 'monokai'

Syntax

code instance-attribute

code: str

dedent instance-attribute

dedent: bool

line_numbers instance-attribute

line_numbers: bool

start_line instance-attribute

start_line: int

line_range instance-attribute

line_range: Optional[Tuple[Optional[int], Optional[int]]]

highlight_lines instance-attribute

highlight_lines: set

code_width instance-attribute

code_width: Optional[int]

tab_size instance-attribute

tab_size: int

word_wrap instance-attribute

word_wrap: bool

indent_guides instance-attribute

indent_guides: bool

padding instance-attribute

padding: Tuple[int, int, int, int]

lexer property

lexer: str

theme property

theme: Optional[str]

background_color property

background_color: Optional[str]

highlighter property

highlighter: Optional[Union[str, CodeHighlighter, Any]]

from_path classmethod

from_path(path: str, encoding: str = 'utf-8', lexer: Optional[str] = None, theme: Optional[str] = 'monokai', dedent: bool = False, line_numbers: bool = False, line_range: Optional[Tuple[int, int]] = None, start_line: int = 1, highlight_lines: Optional[set] = None, code_width: Optional[int] = None, tab_size: int = 4, word_wrap: bool = False, background_color: Optional[str] = None, indent_guides: bool = False, padding: PaddingDimensions = 0, highlighter: Optional[Union[str, CodeHighlighter, Any]] = None) -> Syntax

guess_lexer classmethod

guess_lexer(path: str, code: Optional[str] = None) -> str

get_theme classmethod

get_theme(name: str) -> str

highlight

highlight(code: str, line_range: Optional[Tuple[Optional[int], Optional[int]]] = None) -> Text

stylize_range

stylize_range(style: StyleType, start: Tuple[int, int], end: Tuple[int, int], style_before: bool = False) -> None

code_highlighters

code_highlighters() -> List[str]

The code highlighters this build has (syntect; lumis in a lumis build).

code_themes

code_themes(highlighter: Optional[str] = None) -> List[str]

The theme names a code highlighter accepts (default: syntect).