all2md.parsers.yaml

YAML to AST converter.

This module provides intelligent conversion from YAML structures to readable document format. By default, it transforms the structure into a hierarchical document with headings, tables, and lists. Alternatively, it can render YAML as a literal code block (via the literal_block option).

Examples

Smart Conversion (default):

Input YAML:

server:
  host: localhost
  port: 8080
users:
  - name: Alice
    role: admin
  - name: Bob
    role: user

Output (as markdown):

# server
* **host**: localhost
* **port**: 8,080

# users
| name | role |
|------|------|
| Alice | admin |
| Bob | user |

Literal Block Mode:

Input YAML (same as above)

Output (as markdown):

server:
  host: localhost
  port: 8080
users:
  - name: Alice
    role: admin
  - name: Bob
    role: user
class all2md.parsers.yaml.YamlParser

Bases: BaseParser

Convert YAML structures to AST representation.

This parser creates a readable document from YAML by converting: - Objects/dicts → heading hierarchies - Arrays of objects → tables - Arrays of primitives → lists - Nested structures → subsections

Parameters:
  • options (YamlParserOptions or None, default = None) – Parser configuration options

  • progress_callback (ProgressCallback or None, default = None) – Optional callback for progress updates

Examples

Basic parsing:

>>> parser = YamlParser()
>>> doc = parser.parse('name: John\\nage: 30')

With options:

>>> options = YamlParserOptions(max_heading_depth=3, sort_keys=True)
>>> parser = YamlParser(options)
>>> doc = parser.parse(yaml_file_path)

Initialize the YAML parser with options and progress callback.

__init__(options: YamlParserOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)

Initialize the YAML parser with options and progress callback.

parse(input_data: str | Path | IO[bytes] | bytes) Document

Parse YAML input into AST Document.

Parameters:

input_data (str, Path, IO[bytes], or bytes) – YAML input to parse. Can be: - File path (str or Path) - File-like object in binary mode - Raw YAML bytes - YAML string

Returns:

AST document node

Return type:

Document

Raises:

ParsingError – If parsing fails

extract_metadata(data: Any) DocumentMetadata

Extract metadata from YAML structure.

Parameters:

data (Any) – YAML data structure

Returns:

Extracted metadata

Return type:

DocumentMetadata