antsibull-docs-parser

1.2.2 · active · verified Wed Apr 15

A Python library for processing Ansible documentation markup, designed for reusability. It originates from `antsibull-docs` and provides a generic API to parse, process, and format Ansible markup. The library is currently at version 1.2.2 and adheres to semantic versioning, with major version 1.x.y releases ensuring no breaking changes to its API.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a simple Ansible documentation markup string using `antsibull-docs-parser` and then convert the resulting Document Object Model (DOM) into a plain text representation. It also shows a basic way to inspect the structure of the parsed DOM. The `parse` function is the main entry point, returning a list of DOM elements.

from antsibull_docs_parser.parser import parse
from antsibull_docs_parser.formatters import to_text

ansible_markup = "This is some B(bold) text and C(code). Here's a M(ansible.builtin.debug) module reference."

# Parse the Ansible markup string into a Document Object Model (DOM)
dom = parse(ansible_markup)

# The DOM is a list of nodes, typically Paragraph objects
print(f"Parsed DOM type: {type(dom)}")
for node in dom:
    print(f"  Node type: {type(node)}")
    # Example: print a specific node representation
    # print(node.to_text())

# Convert the parsed DOM to plain text
plain_text = to_text(dom)
print(f"\nPlain text output: {plain_text}")

# Example of accessing DOM structure (simplified)
# This is a conceptual demonstration; actual DOM traversal depends on use case
if dom and hasattr(dom[0], 'parts'): # Assuming the first element is a Paragraph with parts
    print("\nFirst paragraph parts:")
    for part in dom[0].parts:
        print(f"  - {type(part).__name__}: '{getattr(part, 'text', str(part))}'")

view raw JSON →