Breathe Documentation

repository·main·Indexed 21 days ago

https://github.com/breathe-doc/breathe

Breathe is a Sphinx plugin that integrates Doxygen-generated technical documentation into Sphinx projects, allowing developers to combine C++ code analysis with high-level user documentation. It includes the breathe-apidoc CLI tool for automatically generating reStructuredText (.rst) files from Doxygen XML, as well as directives like DoxygenIndexDirective and AutoDoxygenIndexDirective for rendering code documentation.

Tokens
25.4K
Snippets
103
Records
145
Agent score
72%

What's inside Breathe

  1. Overview of Breathe architecture and subpackages

    main

    Breathe acts as a bridge between Doxygen XML output and Sphinx, converting Doxygen XML nodes into docutils reStructuredText (rst) nodes. The architecture is divided into several functional areas:

    • Directives: The entry point for Sphinx users. It contains the rst directive definitions used in documentation files. The directives submodule handles the registration with Sphinx and wires together the necessary factories.
    • Finder: Responsible for locating specific nodes within the XML files generated by Doxygen. Finders are typically used by directives to locate the relevant XML node before passing it to a renderer.
    • Renderer: Converts Doxygen XML nodes into docutils rst nodes. Breathe focuses on producing rst nodes rather than specific output formats like HTML or LaTeX, leaving the final rendering to Sphinx.
    • Parser: Parses Doxygen XML into a tree of Python objects. Much of this logic is contained in the automatically generated _parser module.
    • Project: Represents a Project, which is the Breathe abstraction for a directory containing Doxygen XML files.
    • Process: Manages the execution of the doxygen process, specifically when using autodoxygen directives.
    • Exception: Provides a base class for all custom Breathe exceptions.
  2. What is Breathe?

    main
    Breathe is a Sphinx plugin that provides beautifully integrated Doxygen output in your user-facing documentation. It bridges the gap between Doxygen's technical understanding of a C++ codebase and Sphinx's high-quality long-form documentation capabilities.
  3. Understand the Doxygen XML structure used by Breathe

    main

    Breathe relies on Doxygen's XML output, which consists of multiple files. The central entry point is always index.xml.

    • index.xml: Contains a list of all generated files and a summary of their contents (e.g., which classes or files are present).
    • Compound Files: For any item in index.xml, the refid attribute points to a specific XML file containing detailed information. You can locate the detailed file by appending .xml to the refid value (e.g., refid="class_test" $\rightarrow$ class_test.xml).

    These compound files contain the specific documentation and markup extracted from your source code.

    <!-- Example index.xml snippet -->
    <doxygenindex ...>
      <compound refid="class_test" kind="class">
        <name>Test</name>
        <member refid="class_test_1a45b6a232a4499f8ce37062eab5451570" kind="function">
          <name>member</name>
        </member>
      </compound>
      <compound refid="func_8h" kind="file">
        <name>func.h</name>
      </compound>
    </doxygenindex>
  4. Use Sphinx domains to link to Breathe output

    main
    Breathe provides limited support for Sphinx domains, allowing you to use standard Sphinx domain roles to create cross-references to the documentation generated by Breathe directives. This enables linking to classes, functions, types, and enum values using the appropriate domain prefix (e.g., :cpp: or :c:).
  5. Common options for Breathe directives

    main

    Most Breathe directives support a set of standard options to control which Doxygen project or path is used, and how the output is rendered:

    • :project: <name>: Specifies which project (defined in breathe_projects) to use. Overrides the default project.
    • :path: <path>: Directly specifies the folder containing the Doxygen XML output. Overrides both the project and default project.
    • :no-link:: Prevents Breathe from generating document targets for the content. Use this to repeat information in multiple places without creating duplicate Sphinx targets.
    • :outline:: Instructs Breathe to output only the raw code definitions, omitting additional description information.

    Note: If neither :project: nor :path: is provided, Breathe expects the breathe_default_project configuration value to be set.

  6. How Breathe works: Parser, Finders, and Renderers

    main

    Breathe operates through three main functional stages to transform Doxygen XML into Sphinx documentation:

    1. Parser (breathe.parser): Reads the Doxygen XML output and creates a hierarchy of Python objects representing the data.
    2. Finders (breathe.finder): Searches the object hierarchy created by the parser to locate specific reference objects (e.g., a specific class or function requested by a directive).
    3. Renderers (breathe.renderer): Takes the objects found by the finders and produces reStructuredText (RST) nodes. Renderers typically traverse object hierarchies to render objects and their descendants.

    The data flow is: Code $\rightarrow$ Doxygen $\rightarrow$ XML $\rightarrow$ Breathe Parser $\rightarrow$ Breathe Filter $\rightarrow$ Breathe Finder $\rightarrow$ Breathe Renderer $\rightarrow$ RST Nodes $\rightarrow$ Sphinx $\rightarrow$ HTML/LaTeX.

  7. Understand the current limitations of Inline Parameter Documentation

    main
    Breathe's inline parameter documentation feature is currently limited in its ability to position parameters within the final description. By default, parameters are inserted at the top of the detailed description block. This results in parameters appearing between the brief description and the detailed description text, rather than at the end of the detailed description. This behavior is a known limitation and is subject to future improvements.
  8. LaTeX math implementation details and limitations

    main

    Breathe implements math support by using an internal reStructuredText node provided by sphinx.ext.mathbase. This node is subsequently picked up and rendered by the math extension specified in your Sphinx conf.py.

    Limitations:

    • Breathe does not pass additional options through to the math node.
    • Currently, settings such as :label: and :nowrap: are not supported for math formulas.
  9. Supported list types in Doxygen documentation

    main

    Breathe supports various list formats within Doxygen documentation. When using Breathe directives (like .. doxygenclass::) to render documentation, the following list styles are supported:

    Unordered Lists

    You can create unordered lists using several prefix styles:

    • + prefix
    • - prefix
    • ** *** prefix
    • HTML tags: Using <ul> and <li> tags.

    Numbered Lists

    • Auto-numbered: Using the -# prefix.
    • Arabic numerals: Using standard 1. 2. ... formatting.

    Note: Numbered lists currently only support Arabic numerals.

    Nested Lists

    Nested lists are supported in any combination, provided they follow valid Doxygen markup rules.

  10. Support for Doxygen tables in Breathe

    main
    Breathe supports rendering tables that are defined within Doxygen documentation. These tables can be generated using either standard Markdown syntax or Doxygen-specific syntax. When Breathe processes a Doxygen class or function that contains a table, it renders the table structure into the final documentation output (e.g., Sphinx/reStructuredText).
  11. Understand differences in heading rendering between Breathe, Doxygen, and Autodoc

    main

    Because Breathe bridges the gap between Doxygen's XML output and Sphinx's Docutils model, heading rendering behavior differs from standard Doxygen HTML output:

    • Doxygen HTML: Supports both HTML and Markdown syntax for headings in comments, rendering them as standard HTML heading tags (<h1>, <h2>, etc.).
    • Breathe (Sphinx): RestructuredText (the format used by Sphinx) only allows headings at the start of document sections. Consequently, arbitrary headings found within Doxygen comments cannot be rendered as true HTML heading tags; instead, Breathe renders them as emphasized text in the final output.
  12. How Finders locate objects in the hierarchy

    main

    Finders are responsible for navigating the Python object hierarchy produced by the parser to find a single target node for the renderers.

    Key Mechanics:

    • Entry Points: Finders use the parser's entry points (found in breathe.parser.doxygen.compound and breathe.parser.doxygen.index) to parse the XML and build the hierarchy.
    • Filtering: Finders use Filter objects to determine if a node matches the search criteria. Filters can represent logical conditions like and or or and can match at different levels of the XML hierarchy.
    • Recursive Search Pattern: The search often follows a hierarchical pattern. For example, a DoxygenTypeSubItemFinder might look at the root, find a match for a compound node, and then create a CompoundTypeSubItemFinder to look at members. If a member matches, it might create a MemberTypeSubItemFinder and then parse the corresponding detailed XML file (using the refid + .xml logic) to continue the search deeper.