all2md.renderers.ini
INI rendering from AST.
This module provides the IniRenderer class which extracts section-based data from AST documents and converts it to INI format. The primary use case is extracting configuration from markdown documentation as INI files.
Examples
- Extract configuration from markdown:
- Input markdown:
# server * host: localhost * port: 8080
# database * name: mydb * timeout: 30
- Output INI:
[server] host = localhost port = 8080
[database] name = mydb timeout = 30
- class all2md.renderers.ini.RawConfigParser
Bases:
RawConfigParserCustom ConfigParser that preserves case.
- optionxform(optionstr: str) str
Override to preserve case of option names.
- class all2md.renderers.ini.IniRenderer
Bases:
BaseRendererRender AST to INI format by extracting section-based data.
This renderer extracts sections and key-value pairs from AST documents and converts them to INI format. Level-1 headings become sections, and definition lists (bold keys with values) become key-value pairs.
- Parameters:
options (IniRendererOptions or None, default = None) – INI rendering options
Examples
Basic usage:
>>> from all2md.ast import Document, Heading, List, ListItem, Paragraph, Strong, Text >>> from all2md.renderers.ini import IniRenderer >>> heading = Heading(level=1, content=[Text(content="server")]) >>> list_item = ListItem(children=[ ... Paragraph(content=[ ... Strong(content=[Text(content="host")]), ... Text(content=": localhost") ... ]) ... ]) >>> list_node = List(items=[list_item], ordered=False) >>> doc = Document(children=[heading, list_node]) >>> renderer = IniRenderer() >>> ini_text = renderer.render_to_string(doc)
Initialize the INI renderer with options.
- __init__(options: IniRendererOptions | None = None)
Initialize the INI renderer with options.
- class all2md.renderers.ini.DataExtractor
Bases:
objectExtractor that walks AST and extracts section-based data.
This class walks the AST and extracts sections (from headings) and key-value pairs (from definition lists).
- Parameters:
options (IniRendererOptions) – Rendering options
Initialize the data extractor.
- __init__(options: IniRendererOptions)
Initialize the data extractor.