Doc¶
Utilities for parsing and formatting documentation.
- final class yuio.doc.Formatter(ctx: ReprContext, *, allow_headings: bool = True)¶
A formatter suitable for displaying RST/Markdown documents in the terminal.
- Parameters:
ctx – a
ReprContextthat’s used to colorize or wrap rendered document.allow_headings – if set to
False, headings are rendered as paragraphs.
- format(
- node: AstBase,
- /,
Format a parsed document.
- Parameters:
node – AST node to format.
- Returns:
rendered document as a list of individual lines without newline characters at the end.
- class yuio.doc.DocParser¶
Base class for document parsers.
- abstractmethod parse(s: str, /) Document¶
Parse the given document and return its AST structure.
- Parameters:
s – document to parse.
- Returns:
document AST.
- abstractmethod parse_paragraph(s: str, /) list[str | TextRegion]¶
Parse inline markup in the given paragraph.
- Parameters:
s – paragraph to parse.
- Returns:
inline AST.
AST¶
- class yuio.doc.AstBase¶
Base class for all AST nodes that represent parsed Markdown and RST documents.
- class yuio.doc.Raw(*, raw: ColorizedString)¶
Embeds already formatted paragraph into the document.
- raw: ColorizedString¶
Raw colorized string to add to the document.
- class yuio.doc.Text(*, items: list[str | TextRegion])¶
Base class for all text-based AST nodes, i.e. paragraphs, headings, etc.
- items: list[str | TextRegion]¶
Text lines as parsed from the original document.
- class yuio.doc.TextRegion(*args: str | TextRegion)¶
Text region with special formatting.
- content: list[str | TextRegion]¶
Region contents.
- class yuio.doc.Container(*, items: list[TAst])¶
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.doc.ThematicBreak¶
Represents a visual break in text, a.k.a. an asterism.
- class yuio.doc.Heading(*, items: list[str | TextRegion], level: int)¶
Represents a heading.
- class yuio.doc.Paragraph(*, items: list[str | TextRegion])¶
Represents a regular paragraph.
- class yuio.doc.Admonition(
- *,
- items: list[TAst],
- title: list[str | TextRegion],
- type: str,
Represents an admonition block.
- title: list[str | TextRegion]¶
Main title.
- class yuio.doc.FootnoteContainer(*, items: list[TAst])¶
Container for footnotes, enables compact rendering.
- class yuio.doc.ListEnumeratorKind(*values)¶
For enumerated lists, represents how numbers should look.
- NUMBER = 'NUMBER'¶
Numeric, i.e.
1, 2, 3.
- SMALL_LETTER = 'SMALL_LETTER'¶
Small letters, i.e.
a, b, c.
- CAPITAL_LETTER = 'CAPITAL_LETTER'¶
Capital letters, i.e.
A, B, C.
- SMALL_ROMAN = 'SMALL_ROMAN'¶
Small roman numerals, i.e.
i, ii, iii.
- CAPITAL_ROMAN = 'CAPITAL_ROMAN'¶
Capital roman numerals, i.e.
I, II, III.
- class yuio.doc.ListMarkerKind(*values)¶
For enumerated lists, represents how numbers are stylized.
- DOT = 'DOT'¶
Dot after a number, i.e.
1..
- PAREN = 'PAREN'¶
Paren after a number, i.e.
1).
- ENCLOSED = 'ENCLOSED'¶
Parens around a number, i.e.
(1).
- class yuio.doc.ListItem(*, items: list[TAst], number: int | None)¶
A possibly numbered element of a list.
- class yuio.doc.List(
- *,
- items: list[TAst],
- enumerator_kind: ListEnumeratorKind | str | None = None,
- marker_kind: ListMarkerKind | None = None,
A collection of list items.
- enumerator_kind: ListEnumeratorKind | str | None¶
Enumerator kind for numbered lists, or symbol for bullet lists.
- marker_kind: ListMarkerKind | None¶
Marker kind for numbered lists.
- class yuio.doc.Cut¶
Stops rendering of the container.