Remote content#
2026-09-01
3 min read time
Use the remote-content directive to pull an .rst file from another GitHub
repository into the current page at build time. It selects the branch or tag of
the source repository that matches the version being built, so a release build
inlines release content and a development build inlines development content.
Beyond inlining, the directive rewrites :doc: cross-references to external
URLs (or remaps them to local pages), downloads referenced images, applies text
and regex replacements, adds widths to CSV tables, and can fix common LaTeX math
issues.
Enabling the extension#
The directive is opt-in. Add it to extensions in conf.py:
extensions = [
"rocm_docs",
"rocm_docs.remote_content",
]
Basic usage#
.. remote-content::
:repo: ROCm/ROCm
:path: docs/about/what-is-rocm.rst
:default_branch: develop
On a release build (a docs-X.Y.Z branch, or a Read the Docs tag build), the
directive fetches docs/about/what-is-rocm.rst from the matching tag. Otherwise
it falls back to default_branch.
Version selection#
The target ref is chosen as follows:
If the build is a release (the
versionisX.Y.Zand one of: the local branch is adocs/branch,READTHEDOCS_VERSION_TYPEistag, or the version appears in theREADTHEDOCS_VERSIONslug), the ref is<tag_prefix><version>.Otherwise the ref is
default_branch.
If a release fetch fails (for example, the tag does not exist yet), the directive
retries once against default_branch.
Options#
Option |
Description |
|---|---|
|
Source repository as |
|
Path to the |
|
Branch to use when the build is not a release, and as the release fallback. |
|
Prefix prepended to the version to form the release tag (e.g. |
|
Include the file starting from this line number. |
|
Literal text replacements, |
|
Regex replacements, |
|
Override the project name used when building external |
|
Override the base URL used for external |
|
|
|
Remap |
|
Add a |
|
Set to |
Handling :doc: references#
By default, each :doc: role in the fetched content is rewritten to an absolute
URL on the published documentation site, so links resolve from the page that
inlined the content. You can change this per target:
doc_ignoreleaves a target as a normal:doc:role (useful when the target also exists locally or is resolved by intersphinx).doc_remaprewrites a target to a different local page. Useold|newto keep the original link text, orold|new_text|newto also change the displayed text.
Namespaced references such as :doc:rocm:about/release-notes`` are left
untouched so intersphinx can resolve them, unless a doc_remap entry matches.
Configuration#
The base URL used to build external :doc: links defaults to
https://rocm.docs.amd.com/projects. Override it globally in conf.py:
rocm_docs_remote_content_docs_base = "https://rocm.docs.amd.com/projects"
The per-directive docs_base_url option takes precedence over this value.
Images#
Images referenced by the fetched content are downloaded into
_remote_images/<owner>_<name>/ under the Sphinx source directory and the image
nodes are updated to point at the local copies, so they render without depending
on the remote host at serve time. Absolute image URLs are left unchanged.