sphinx-contrib-confluencebuilder
repository·main·Indexed 43 days ago
https://github.com/sphinx-contrib/confluencebuilderA 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.
What's inside sphinx-contrib-confluencebuilder
- Atlassian Confluence Builder for Sphinx is a Sphinx extension designed to build Confluence-supported format files (such as Confluence storage format) and publish them directly to a Confluence instance. It is a community-provided tool and is not affiliated with Atlassian.
Use Smart Links roles (Confluence Cloud only)
mainSmart links render as cards and are only supported when publishing to Confluence Cloud.
Link to a document
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`.Link to a URL
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`.Archive or purge legacy Confluence pages
mainYou can automatically manage pages in Confluence that are no longer part of your current Sphinx documentation set.
Archiving Pages
Set
confluence_cleanup_archive = Trueto 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 = Trueto 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: IfTrue, cleanup is restricted to descendants of theroot_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 = FalseAvoid page name collisions in Confluence spaces
mainConfluence requires unique page names within a single space. The
confluencebuilderextension 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.
Third-party extension support compatibility
mainSupport for third-party Sphinx extensions in
confluencebuildervaries. While many extensions work with thehtmlbuilder, 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-designonly 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 theconfluence_tab_macroconfigured. - 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:
- Implement support within the third-party extension itself.
- Propose non-intrusive changes to
confluencebuilder. - Create a wrapper extension that binds both extensions together.
- Limited Support: Some extensions may have unexpected formatting or restricted features (e.g.,
Markdown support via MyST Parser
mainYou 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_htmloption to allow raw HTML, but this is unsupported. Enabling this may cause content to render incorrectly or fail to publish.
Use environment variables for configuration fallback
mainStarting 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_publishis not set inconf.py, the extension will check theCONFLUENCE_PUBLISHenvironment variable.Use the confluence builder to generate multiple Confluence documents
mainThe
confluencebuilder 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-buildcommand with the-Mflag specifyingconfluence.sphinx-build -M confluence . _build -E -aVerify the installation of confluencebuilder
mainAfter installation, you can verify that the package is correctly installed and check its version by running the following command in your terminal.
python -m sphinxcontrib.confluencebuilder --versionSet up a new Sphinx project for ConfluenceBuilder
mainIf 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.quickstartOption 2: Minimalistic Setup
- Create an
index.rstfile:
My documentation ================ This is a test document.- Create a
conf.pyfile with an empty extensions list:
extensions = []After completing either method, proceed to Configuring to use this extension.
sphinx-quickstart- Create an
Use the singleconfluence builder to generate one Confluence document
mainThe
singleconfluencebuilder (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-buildcommand with the-Mflag specifyingsingleconfluence.sphinx-build -M singleconfluence . _build -E -aRestrict Confluence directives to the Confluence builder
mainIf 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_confluenceorbuilder_singleconfluence... only:: builder_confluence or builder_singleconfluence .. confluence_metadata:: :labels: label-test