all2md.options.toml
Options for TOML parsing and rendering.
This module defines configuration options for converting between TOML and AST. The parser converts TOML structures to readable document format, while the renderer extracts tables and structured data from documents back to TOML.
- class all2md.options.toml.TomlParserOptions
Bases:
BaseParserOptionsConfiguration options for TOML to AST parsing.
By default the parser emits the TOML as a fenced code block (
literal_block). Setliteral_block=Falseto convert TOML structures into a human-readable document instead: - Sections/tables become heading hierarchies - Arrays of tables become markdown tables - Arrays of primitives become lists - Nested structures become subsections- Parameters:
max_heading_depth (int, default = 6) – Maximum nesting depth for headings. Deeper structures will be rendered as definition lists or nested paragraphs instead of headings.
array_as_table_threshold (int, default = 1) – Minimum number of items in an array to render it as a table (for arrays of objects with consistent keys). Set to 2 or higher to render single-item arrays as definition lists instead of tables.
flatten_single_keys (bool, default = True) – If True, flatten objects that contain only a single key. For example, {“wrapper”: {“actual_data”: “value”}} becomes “# actual_data” instead of “# wrapper” > “## actual_data”.
include_type_hints (bool, default = False) – If True, add metadata hints about the original TOML types (useful for round-trip conversion or debugging).
pretty_format_numbers (bool, default = True) – If True, format large numbers with thousand separators for readability.
sort_keys (bool, default = False) – If True, sort object keys alphabetically when rendering.
literal_block (bool, default = True) – If True (the default), render TOML as a literal fenced code block, preserving the native syntax. Set to False to convert into a structured document (headings, tables for arrays of objects, lists).
- literal_block: bool = True
- max_heading_depth: int = 6
- array_as_table_threshold: int = 1
- flatten_single_keys: bool = True
- include_type_hints: bool = False
- pretty_format_numbers: bool = True
- sort_keys: bool = False
- __init__(extract_metadata: bool = False, literal_block: bool = True, max_heading_depth: int = 6, array_as_table_threshold: int = 1, flatten_single_keys: bool = True, include_type_hints: bool = False, pretty_format_numbers: bool = True, sort_keys: bool = False) None
- class all2md.options.toml.TomlRendererOptions
Bases:
BaseRendererOptionsConfiguration options for AST to TOML rendering.
The renderer extracts structured data from markdown documents, primarily focusing on tables but optionally including lists and other elements.
- Parameters:
extract_mode (Literal["tables", "lists", "both"], default = "tables") – What to extract from the document: - “tables”: Extract only tables as arrays of objects - “lists”: Extract only lists as arrays - “both”: Extract both tables and lists
type_inference (bool, default = True) – If True, automatically detect and convert types (numbers, booleans). If False, all values remain as strings. Note: TOML does not support null.
table_heading_keys (bool, default = True) – If True, use the preceding heading text as the key name for each table. If False, tables are stored in a flat array.
flatten_single_table (bool, default = False) – If True and only one table is found, return the array directly instead of wrapping it in an object with a key.
include_table_metadata (bool, default = False) – If True, include metadata about table position, source heading, etc.
sort_keys (bool, default = False) – If True, sort keys in output TOML.
- extract_mode: Literal['tables', 'lists', 'both'] = 'tables'
- type_inference: bool = True
- table_heading_keys: bool = True
- flatten_single_table: bool = False
- include_table_metadata: bool = False
- sort_keys: bool = False
- __init__(fail_on_resource_errors: bool = False, max_asset_size_bytes: int = 52428800, metadata_policy: MetadataRenderPolicy = <factory>, creator: str | None = 'all2md', extract_mode: Literal['tables', 'lists', 'both']='tables', type_inference: bool = True, table_heading_keys: bool = True, flatten_single_table: bool = False, include_table_metadata: bool = False, sort_keys: bool = False) None