sphinx-contrib-confluencebuilder

repository·main·Indexed 43 days ago

https://github.com/sphinx-contrib/confluencebuilder

A Sphinx extension to build Confluence-compatible markup and publish documentation to Confluence Cloud or Data Center 9.1+ instances. It includes the 'confluence' builder for multiple documents and the 'singleconfluence' builder (v1.3+) for a single document. Supports custom Sphinx nodes, environment variable configuration (v1.9+), and a CLI tool for wiping Confluence spaces.

Tokens
31.4K
Snippets
145
Records
168
Agent score
53%

What's inside sphinx-contrib-confluencebuilder

  1. Use Smart Links roles (Confluence Cloud only)

    main

    Smart links render as cards and are only supported when publishing to Confluence Cloud.

    Use the :confluence_doc: role to define an inlined link to a document. It accepts document names in absolute or relative formats (similar to Sphinx's :doc: role).

    See :confluence_doc:`my-other-page`.

    Use the :confluence_link: role to define an inlined link to a page using a URL.

    See :confluence_link:`https://example.com`.
    See :confluence_doc:`my-other-page`.
    See :confluence_link:`https://example.com`.
  2. Archive or purge legacy Confluence pages

    main

    You can automatically manage pages in Confluence that are no longer part of your current Sphinx documentation set.

    Archiving Pages

    Set confluence_cleanup_archive = True to automatically archive pages in a space or parent page that do not match the current published documents.

    • Warning: This feature uses an experimental Atlassian API and is primarily supported on Confluence Cloud. Using it on Data Center may result in a 500 error.
    • Warning: Publishing a subset of documents while this is enabled may cause unexpected archiving of the documents you didn't include in that specific run.

    Purging Pages

    Set confluence_cleanup_purge = True to permanently remove legacy pages that do not match the current published documents.

    • Warning: Like archiving, this can lead to unexpected results if you only publish a subset of your documentation.

    Cleanup Scoping

    • confluence_cleanup_from_root: If True, cleanup is restricted to descendants of the root_doc_ page. This prevents cleanup from affecting other documentation sets sharing the same parent.
    • confluence_parent_page: If set, cleanup only affects descendants of this specific page/identifier.
    confluence_cleanup_archive = False
    confluence_cleanup_purge = False
    confluence_cleanup_from_root = False
  3. Avoid page name collisions in Confluence spaces

    main

    Confluence requires unique page names within a single space. The confluencebuilder extension uses the document's title to determine whether to create a new page or update an existing one.

    If your Sphinx documentation contains a page title that matches an existing manually created page in the target Confluence space, the extension will update and move the existing page to become a child of the documentation container, rather than creating a new nested page. This can mangle manually prepared content.

    To prevent this, use one of the following configuration options to ensure Sphinx-generated pages have unique names that do not collide with existing content:

    • confluence_publish_prefix: Adds a prefix to all published page titles.
    • confluence_publish_postfix: Adds a postfix to all published page titles.
  4. Third-party extension support compatibility

    main

    Support for third-party Sphinx extensions in confluencebuilder varies. While many extensions work with the html builder, they may not integrate correctly with the Confluence builder due to implementation details or reliance on features (like JavaScript) that standard Confluence instances do not support.

    Key considerations:

    • Limited Support: Some extensions may have unexpected formatting or restricted features (e.g., sphinx-design only supports single cards, not side-by-side layouts).
    • Macro Requirements: Extensions that render interactive elements like tabs (e.g., sphinx-inline-tabs, sphinx-tabs) often require a Confluence instance with a third-party macro installed and the confluence_tab_macro configured.
    • Image Formats: Several diagramming extensions (e.g., sphinxcontrib-actdiag, sphinxcontrib-blockdiag, sphinxcontrib-nwdiag, sphinxcontrib-seqdiag) are limited to PNG output and cannot currently be configured for SVG.
    • Integration Strategies: If an extension is not working, developers can:
      1. Implement support within the third-party extension itself.
      2. Propose non-intrusive changes to confluencebuilder.
      3. Create a wrapper extension that binds both extensions together.
  5. Markdown support via MyST Parser

    main

    You can render Markdown content by using Sphinx with the MyST Parser. While most content can be translated to Confluence storage format, there are restrictions:

    • HTML Content: Directives that generate HTML or raw HTML content (including line breaks, strikethroughs, etc.) are not accepted by default.
    • Workaround: You can attempt to use the confluence_permit_raw_html option to allow raw HTML, but this is unsupported. Enabling this may cause content to render incorrectly or fail to publish.
  6. Use environment variables for configuration fallback

    main

    Starting from version 1.9, all configuration options provided by this extension can be set via environment variables as a fallback if they are not explicitly defined in conf.py.

    For example, if confluence_publish is not set in conf.py, the extension will check the CONFLUENCE_PUBLISH environment variable.

  7. Use the confluence builder to generate multiple Confluence documents

    main

    The confluence builder processes a Sphinx documentation set and generates a separate Confluence-compatible document for each individual document in your source. These generated documents can then be published to a configured Confluence instance.

    To run this builder, use the sphinx-build command with the -M flag specifying confluence.

    sphinx-build -M confluence . _build -E -a
  8. Set up a new Sphinx project for ConfluenceBuilder

    main

    If you are starting a new documentation project, you can either use the Sphinx quick-start utility or create a minimalistic manual setup.

    Option 1: Sphinx Quick-start

    Open a terminal in your target directory and run:

    sphinx-quickstart
    # or
    python -m sphinx.cmd.quickstart
    # or
    python -m sphinx.quickstart

    Option 2: Minimalistic Setup

    1. Create an index.rst file:
    My documentation
    ================
    
    This is a test document.
    1. Create a conf.py file with an empty extensions list:
    extensions = []

    After completing either method, proceed to Configuring to use this extension.

    sphinx-quickstart
  9. Use the singleconfluence builder to generate one Confluence document

    main

    The singleconfluence builder (added in version 1.3) processes a Sphinx documentation set and collapses the entire documentation set into a single Confluence-compatible document. This is useful when you want your entire Sphinx project to appear as one large page in Confluence.

    To run this builder, use the sphinx-build command with the -M flag specifying singleconfluence.

    sphinx-build -M singleconfluence . _build -E -a
  10. Restrict Confluence directives to the Confluence builder

    main

    If your Sphinx project uses multiple builders (e.g., HTML and Confluence), you can prevent Confluence-specific directives from causing errors in other builders by using the Sphinx :only: directive.

    To ensure a directive only executes when building for Confluence, wrap it in a block targeting builder_confluence or builder_singleconfluence.

    .. only:: builder_confluence or builder_singleconfluence
    
        .. confluence_metadata::
            :labels: label-test