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: RawConfigParser

Custom ConfigParser that preserves case.

optionxform(optionstr: str) str

Override to preserve case of option names.

class all2md.renderers.ini.IniRenderer

Bases: BaseRenderer

Render 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.

render(doc: Document, output: str | Path | IO[bytes] | IO[str]) None

Render AST document to INI file.

Parameters:
  • doc (Document) – AST Document node to render

  • output (str, Path, IO[bytes], or IO[str]) – Output destination

render_to_string(doc: Document) str

Render AST document to INI string.

Parameters:

doc (Document) – AST Document node to render

Returns:

INI string

Return type:

str

class all2md.renderers.ini.DataExtractor

Bases: object

Extractor 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.

extract(doc: Document) dict[str, dict[str, Any]]

Extract data from document.

Parameters:

doc (Document) – Document to extract from

Returns:

Extracted data as {section: {key: value}}

Return type:

dict[str, dict[str, Any]]