all2md.parsers.ini
INI to AST converter.
This module provides intelligent conversion from INI structures to readable document format. By default, it transforms the structure into a hierarchical document with headings and definition lists. Alternatively, it can render INI as a literal code block (via the literal_block option).
Examples
Smart Conversion (default):
Input INI:
[server]
host = localhost
port = 8080
[database]
name = mydb
timeout = 30
Output (as markdown):
# server
* **host**: localhost
* **port**: 8,080
# database
* **name**: mydb
* **timeout**: 30
Literal Block Mode:
Input INI (same as above)
Output (as markdown):
[server]
host = localhost
port = 8080
[database]
name = mydb
timeout = 30
- class all2md.parsers.ini.RawConfigParser
Bases:
RawConfigParserCustom ConfigParser that preserves case.
- optionxform(optionstr: str) str
Override to preserve case of option names.
- class all2md.parsers.ini.IniParser
Bases:
BaseParserConvert INI structures to AST representation.
This parser creates a readable document from INI by converting: - Sections → headings - Key-value pairs → definition lists (bullet lists with bold keys) - Comments → preserved as paragraphs (if supported)
- Parameters:
options (IniParserOptions or None, default = None) – Parser configuration options
progress_callback (ProgressCallback or None, default = None) – Optional callback for progress updates
Examples
Basic parsing:
>>> parser = IniParser() >>> doc = parser.parse('[server]\\nhost = localhost\\nport = 8080')
With options:
>>> options = IniParserOptions(preserve_case=True, allow_no_value=True) >>> parser = IniParser(options) >>> doc = parser.parse(ini_file_path)
Initialize the INI parser with options and progress callback.
- __init__(options: IniParserOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)
Initialize the INI parser with options and progress callback.
- parse(input_data: str | Path | IO[bytes] | bytes) Document
Parse INI input into AST Document.
- Parameters:
input_data (str, Path, IO[bytes], or bytes) – INI input to parse. Can be: - File path (str or Path) - File-like object in binary mode - Raw INI bytes - INI string
- Returns:
AST document node
- Return type:
- Raises:
ParsingError – If parsing fails
- extract_metadata(parser: RawConfigParser | ConfigParser) DocumentMetadata
Extract metadata from INI structure.
- Parameters:
parser (RawConfigParser or ConfigParser) – Parsed INI configuration
- Returns:
Extracted metadata
- Return type: