API Reference
Python API
For visitor- and plugin-style customization, see Extension API.
The main class is RestructuredText. Several aliases are
provided for convenience; they are identical:
Name |
Import path |
|---|---|
|
|
|
|
|
|
|
|
|
|
- class rich_rst.RestructuredText(markup: str, code_theme: str | SyntaxTheme | None = 'monokai', show_errors: bool | None = True, guess_lexer: bool | None = False, default_lexer: str | None = 'python', sphinx_compat: bool | None = True, filename: str | None = '<rst-document>')[source]
A reStructuredText renderable for rich.
- Parameters:
markup (str) – A string containing reStructuredText markup.
code_theme (Optional[Union[str, SyntaxTheme]]) – Pygments theme for code blocks. Defaults to “monokai”.
show_errors (Optional[bool]) – Whether to show system_messages aka errors and warnings.
guess_lexer (Optional[bool]) – Whether to guess lexers for code blocks without specified language.
default_lexer (Optional[str]) – Which lexer to use if no lexer is guessed or found. Defaults to “python”
sphinx_compat (Optional[bool]) – Enable compatibility with Sphinx roles (func, meth, class, etc.) commonly used in Python docstrings. When enabled, these roles render as inline code instead of errors. Defaults to True for better compatibility with Python documentation.
filename (Optional[str]) – A file name to use for error messages, useful for debugging purposes. Defaults to “<rst-document>”
Command-line interface
rich-rst ships with a CLI module that renders RST files (or stdin)
directly to the terminal.
Usage
python -m rich_rst PATH [options]
python -m rich_rst - [options] # read from stdin
PATH is required unless you use --list-html-themes.
Options
Flag |
Description |
|---|---|
|
Force ANSI colour output even on non-terminal streams. |
|
Show the installed package version and exit. |
|
File encoding (default: |
|
Output width in columns (auto-detected by default). |
|
|
|
Pygments theme used for syntax-highlighted code blocks (default:
|
|
Show line numbers in syntax-highlighted code blocks. |
|
Path to save the rendered output as an HTML file. |
|
Hard-wrap long lines. |
|
Enable soft-wrap mode (lines are wrapped by the terminal). |
|
Guess the syntax-highlighting language for code blocks that do not specify one. |
|
Fallback language for code blocks when none is detected (default:
|
|
Show RST parse errors and warnings. |
|
Theme for |
|
Print available HTML themes and exit. |
|
Write rendered plain-text output to a file instead of stdout. |