all2md.renderers.yaml
YAML rendering from AST.
This module provides the YamlRenderer class which extracts structured data from AST documents and converts it to YAML format. The primary use case is extracting tables from markdown documentation as YAML structures.
Examples
Extract tables from markdown:
Input markdown:
# Users
| name | age | active |
|------|-----|--------|
| Alice | 30 | true |
| Bob | 25 | false |
Output YAML:
Users:
- name: Alice
age: 30
active: true
- name: Bob
age: 25
active: false
- class all2md.renderers.yaml.YamlRenderer
Bases:
BaseRendererRender AST to YAML format by extracting structured data.
This renderer extracts tables and lists from AST documents and converts them to YAML structures. Tables become arrays of objects, with column headers as keys. Preceding headings are used as structure keys.
- Parameters:
options (YamlRendererOptions or None, default = None) – YAML rendering options
Examples
Basic usage (extract tables):
>>> from all2md.ast import Document, Table, TableRow, TableCell, Text, Heading >>> from all2md.renderers.yaml import YamlRenderer >>> table = Table( ... header=TableRow(cells=[ ... TableCell(content=[Text(content="name")]), ... TableCell(content=[Text(content="value")]) ... ]), ... rows=[ ... TableRow(cells=[ ... TableCell(content=[Text(content="timeout")]), ... TableCell(content=[Text(content="30")]) ... ]) ... ] ... ) >>> heading = Heading(level=1, content=[Text(content="Configuration")]) >>> doc = Document(children=[heading, table]) >>> renderer = YamlRenderer() >>> yaml_text = renderer.render_to_string(doc)
Extract lists as arrays:
>>> from all2md.options.yaml import YamlRendererOptions >>> options = YamlRendererOptions(extract_mode="both") >>> renderer = YamlRenderer(options)
Initialize the YAML renderer with options.
- __init__(options: YamlRendererOptions | None = None)
Initialize the YAML renderer with options.
- class all2md.renderers.yaml.DataExtractor
Bases:
objectExtractor that walks AST and extracts structured data.
This class walks the AST and extracts tables and lists into structured data according to the renderer options.
- Parameters:
options (YamlRendererOptions) – Rendering options
Initialize the data extractor.
- __init__(options: YamlRendererOptions)
Initialize the data extractor.