Antsibull Docutils Helpers

1.4.0 · active · verified Thu Apr 16

Antsibull-docutils is a Python library that provides docutils helpers used primarily by other Antsibull tools for building Ansible documentation. It offers functionalities like finding code blocks within reStructuredText (RST) files. The library is currently at version 1.4.0 and is actively maintained within the Ansible community, showing a regular release cadence with recent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `find_code_blocks` to extract code snippets from a reStructuredText (RST) string. The function returns a list of CodeBlock objects, each containing details about the found block, such as its content, language, and line number.

from antsibull_docutils.rst_code_finder import find_code_blocks

rst_content = '''
.. code-block:: python

    print("Hello from Python!")

A normal paragraph.

.. code-block:: yaml

    - name: Example task
      ansible.builtin.debug:
        msg: "YAML here"
'''

code_blocks = find_code_blocks(rst_content)

for block in code_blocks:
    print(f"Found code block (type: {block.directive_arg}, line {block.line_number}):")
    print(block.code)
    print("---")

view raw JSON →