Md
Yuio’s primary format for higher-level io is Markdown (well, a reasonably rich subset of it).
Formatting markdown
- class yuio.md.MdFormatter(theme: Theme, *, width: int | None = None, allow_headings: bool = True)[source]
A simple markdown formatter suitable for displaying reach text in the terminal.
All CommonMark block markup is supported:
headings:
# Heading 1 ## Heading 2
Yuio has only two levels of headings. Headings past level two will look the same as level two headings (you can adjust theme to change this).
If allow_headings is set to false, headings look like paragraphs.
lists, numbered lists, quotes:
- List item 1, - list item 2. 1. Numbered list item 1, 1. numbered list item 2. > Quoted text.
fenced code blocks with minimal syntax highlighting (see
SyntaxHighlighter
):```python for i in range(5, 8): print( f"Hello, world! " "This is {i}th day past the apocalypse." ) ```
Yuio supports
python
,traceback
, andbash
syntaxes.
Inline markdown only handles inline code blocks:
This is `code`. It will be rendered as code. Other inline styles, such as _italic_, are not supported!
However, color tags are supported, so you can highlight text as follows:
This is <c b>bold text</c>. It will be rendered bold.
- format(s: str, /) ColorizedString [source]
Format a markdown document.
- parse(s: str, /) AstBase [source]
Parse a markdown document and return an AST node.
Warning
This is an experimental API which can change within a minor release.
- format_node(node: AstBase, /) ColorizedString [source]
Format a parsed markdown document.
Warning
This is an experimental API which can change within a minor release.
Highlighting code
Yuio supports basic code highlighting; it is just enough to format help messages for CLI, and color tracebacks when an error occurs.
- class yuio.md.SyntaxHighlighter[source]
- abstract property syntaxes: List[str]
List of syntax names that should be associated with this highlighter.
The first name in this list is a canonical syntax name, i.e. it will be used to look up colors in a theme.
- property syntax: str
The primary syntax name for this highlighter.
This name is used to look up colors in a theme.
- classmethod register_highlighter(highlighter: SyntaxHighlighter)[source]
Register a highlighter in a global registry, and allow looking it up via the
get_highlighter()
method.
- classmethod get_highlighter(syntax: str, /) SyntaxHighlighter [source]
Look up highlighter by a syntax name.
Markdown AST
Warning
This is an experimental API which can change within a minor release.
- class yuio.md.AstBase[source]
Base class for all AST nodes that represent parsed markdown document.
- class yuio.md.Text(lines: List[str])[source]
Base class for all text-based AST nodes, i.e. paragraphs.
- class yuio.md.Container(items: List[TAst])[source]
Base class for all container-based AST nodes, i.e. list items or quotes.
This class works as a list of items. Usually it contains arbitrary AST nodes, but it can also be limited to specific kinds of nodes via its generic variable.
- class yuio.md.Document(items: List[TAst])[source]
Root node that contains the entire markdown document.