Restructured_Text Module

Utilities for formatting data using RST markup

author:

Doug Skrypa

cli_command_parser.formatting.restructured_text.rst_bar(text: str | int, level: int = 1) str[source]
cli_command_parser.formatting.restructured_text.rst_header(text: str, level: int = 1, overline: Bool = False) str[source]
cli_command_parser.formatting.restructured_text.spaced_rst_header(text: str, level: int = 1, before: bool = True) Iterator[str][source]
cli_command_parser.formatting.restructured_text.rst_directive(directive: str, args: str = None, options: dict[str, Any] = None, indent: int = 4, check: Bool = False) str[source]
cli_command_parser.formatting.restructured_text.rst_toc_tree(name: str, content_fmt: str, contents: Strings, max_depth: int = 4, **kwargs) str[source]
Parameters:
  • name – The name of the section. Written as a header above the toctree directive.

  • content_fmt – The format string used to indent/prefix each entry in the contents to include in this table of contents.

  • contents – The names of the documents to include in this table of contents.

  • max_depth – The maximum depth of the table of contents tree. Use -1 to allow unlimited depth.

  • kwargs – Keyword arguments to be included as :key: <value> options to the toctree directive.

Returns:

The RST header and table of contents directive as a string.

cli_command_parser.formatting.restructured_text.rst_list_table(data: dict[str, str], value_pad: int = 20) str[source]
class cli_command_parser.formatting.restructured_text.RstTable(title: str = None, subtitle: str = None, headers: Sequence[str] = None, *, show_title: Bool = True, use_table_directive: Bool = True)[source]

Bases: object

Parameters:
  • title – The title for this table. Only displayed if show_title is True.

  • subtitle – Passed as an option to the table directive if header is True.

  • headers – Columns headers to use before the first row.

  • show_title – If True, and a title was provided, then that title will be emitted as a rubric directive by iter_build() before the beginning of this table.

  • use_table_directive – If True, then the table directive will be used before the body of this table.

title
subtitle
show_title
use_table_directive
classmethod from_dicts(rows: RowMaps, columns: Sequence[T] = None, auto_headers: Bool = False, **kwargs) RstTable[source]

Initialize a RstTable using the given keyword arguments, and populate its rows using the given dicts and add_dict_rows().

classmethod from_dict(data: Mapping[OptStr, OptStr], **kwargs) RstTable[source]

Initialize a RstTable using the given keyword arguments, and populate its rows using the given dict and add_kv_rows().

property widths: tuple[int, ...][source]
add_dict_rows(rows: RowMaps, columns: Sequence[T] = None, add_header: Bool = False)[source]

Add a row for each dict in the given sequence of rows, where the keys represent the columns.

add_kv_rows(data: Mapping[OptStr, OptStr])[source]

Add a row for each key=value pair in the given dict, where the first column contains the key and the second column contains the value.

add_rows(rows: Iterable[Iterable[OptStr]])[source]
add_row(*columns: OptStr, index: int = None, header: bool = False)[source]

Add a row to the table.

Parameters:
  • columns – The string values to use as columns in a single row

  • index – If specified, insert the new row at the specified index. By default, the new row is appended to the list of rows.

  • header – If True, this row will be treated as a header row. Does not affect insertion order.

iter_build() Iterator[str][source]
class cli_command_parser.formatting.restructured_text.Cell(text: str = '', *, ext_right: bool = False, ext_below: bool = False)[source]

Bases: object

text
lines
width
height
brd_bottom
brd_right
render_upper_bar(width: int) str[source]
render_lower_bar(width: int, char: str = '-') str[source]
render_lines(width: int, max_lines: int) Iterator[str][source]
class cli_command_parser.formatting.restructured_text.Row(cells: list[Cell], header: bool = False)[source]

Bases: object

cells
header
widths() Iterator[int][source]
render_upper_bar(widths: Sequence[int]) str[source]
render_lower_bar(widths: Sequence[int]) str[source]
render_lines(widths: Sequence[int]) Iterator[str][source]