Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Read the Docs user documentation
Light Logo Dark Logo

Getting started

  • Tutorial
  • Adding a documentation project
  • Popular documentation tools
    • Deploying Sphinx on Read the Docs
    • Deploying MkDocs on Read the Docs
    • Deploying Docusaurus on Read the Docs
    • Deploying Markdoc on Read the Docs
    • Deploying mdBook on Read the Docs
    • Deploying VitePress on Read the Docs
    • Deploying Antora on Read the Docs
    • Deploying Zensical on Read the Docs
    • Deploying MyST Markdown on Read the Docs
  • Example projects

Project setup and configuration

  • Configuration file overview
  • Configuration file reference
  • Read the Docs Addons
  • Account authentication methods
  • Automation rules
  • How to create reproducible builds

Build process

  • Build process overview
  • Build process customization
  • Git integration (GitHub, GitLab, Bitbucket)
  • Pull request previews
  • Build failure notifications
  • Environment variable overview
  • Environment variable reference

Hosting documentation

  • Versions
  • Subprojects
  • Localization and Internationalization
  • URL versioning schemes
  • Custom domains
  • URL path prefixes
  • Documentation notifications
  • Canonical URLs
  • Content Delivery Network (CDN) and caching
  • Sitemap support
  • 404 Not Found pages
  • robots.txt support
  • llms.txt support
  • Markdown for AI agents

Reading documentation

  • Offline formats (PDF, ePub, HTML)
  • Visual diff
  • Link previews
  • How to embed content from your documentation
  • Server side search
  • Search query syntax
  • Flyout menu

Maintaining projects

  • Redirects
  • Traffic analytics
  • Search analytics
  • Security logs
  • Status badges
  • How to structure your documentation
  • Best practices for linking to your documentation
  • Security considerations for documentation pages
  • Main content detection
  • AI agent skills
  • Custom script

Business features

  • Business hosting
  • Organizations
  • Single sign-on (SSO)
  • Sharing private documentation
  • How to manage your subscription
  • Privacy levels

How-to guides

  • Project setup and configuration
    • Connecting your Read the Docs account to your Git provider
    • Configuring a Git repository manually
    • Managing custom domains
    • Managing subprojects
    • Hiding a version
    • Using a .readthedocs.yaml file in a sub-folder
    • Using custom URL redirects in documentation projects
  • Build process
    • Setup email notifications
    • Setting up outgoing webhooks
    • Configuring pull request builds
    • Using custom environment variables
    • Managing versions automatically
    • Skip builds based on conditions
  • Upgrading and maintaining projects
    • Creating reproducible builds
    • Using Conda as your Python environment
  • Content, themes and SEO
    • Search engine optimization (SEO) for documentation projects
    • Using traffic analytics
    • Using search analytics
    • Enabling offline formats
    • Embedding content from your documentation
    • Managing translations for Sphinx projects
    • Supporting Unicode in Sphinx PDFs
    • Cross-referencing with Sphinx
    • Linking to other projects with Intersphinx
    • Using Jupyter notebooks in Sphinx
    • Migrating from rST to MyST
    • Adding custom CSS or JavaScript to Sphinx documentation
    • Adding "Edit Source" links on your Sphinx theme
  • Security and access
    • Single sign-on (SSO) with GitHub, GitLab, or Bitbucket
    • Single sign-on (SSO) with Google Workspace
    • Single sign-on (SSO) with SAML
    • Managing Read the Docs teams
    • Creating a project from a private repository
    • Using private Git submodules
    • Installing private python packages
    • Manage maintainers
  • Account management
    • Managing your Read the Docs for Business subscription
    • Configuring two-factor authentication
  • Best practice
    • Deprecating content
    • Best practices for linking to your documentation
    • Creating reproducible builds
    • Search engine optimization (SEO) for documentation projects
    • Hiding a version
  • Troubleshooting problems
    • Troubleshooting build errors
    • Troubleshooting slow builds

Reference

  • Public REST API
    • API v3
    • API v2
    • Server side search API
    • Cross-site requests
  • Frequently asked questions
  • Changelog
  • About Read the Docs
    • Policies and legal documents
      • Abandoned projects policy
      • Unofficial and unmaintained projects policy
      • Privacy Policy
      • Security policy
      • Security reports
      • `Terms of Service <https://about.readthedocs.com/terms-of-service/>`_
      • DMCA takedown policy
        • 2022-06-07
      • Data Processing Addendum (DPA)
        • Sub-processor list
    • Advertising
      • EthicalAds
      • Advertising details
      • Ad blocking
      • Customizing advertising
    • The story of Read the Docs
    • Sponsors of Read the Docs
    • Documentation in scientific and academic publishing
    • Read the Docs open source philosophy
    • Read the Docs team
    • Site support
    • Glossary
  • Developer Documentation
  • Read the Docs website
Back to top
View this page

Adding “Edit Source” links on your Sphinx theme¶

You can use define some Sphinx variables in the html_context to tell Read the Docs Sphinx theme to display “Edit Source” links on each page.

More information can be found on Sphinx documentation.

GitHub¶

If you want to integrate GitHub, these are the required variables to put into your conf.py:

html_context = {
    "display_github": True, # Integrate GitHub
    "github_user": "MyUserName", # Username
    "github_repo": "MyDoc", # Repo name
    "github_version": "master", # Version
    "conf_py_path": "/source/", # Path in the checkout to the docs root
}

They can be used like this:

{% if display_github %}
    <li><a href="https://github.com/{{ github_user }}/{{ github_repo }}
    /blob/{{ github_version }}{{ conf_py_path }}{{ pagename }}.rst">
    Show on GitHub</a></li>
{% endif %}

Bitbucket¶

If you want to integrate Bitbucket, these are the required variables to put into your conf.py:

html_context = {
    "display_bitbucket": True, # Integrate Bitbucket
    "bitbucket_user": "MyUserName", # Username
    "bitbucket_repo": "MyDoc", # Repo name
    "bitbucket_version": "master", # Version
    "conf_py_path": "/source/", # Path in the checkout to the docs root
}

They can be used like this:

{% if display_bitbucket %}
    <a href="https://bitbucket.org/{{ bitbucket_user }}/{{ bitbucket_repo }}
    /src/{{ bitbucket_version}}{{ conf_py_path }}{{ pagename }}.rst'"
    class="icon icon-bitbucket"> Edit on Bitbucket</a>
{% endif %}

Gitlab¶

If you want to integrate Gitlab, these are the required variables to put into your conf.py:

html_context = {
    "display_gitlab": True, # Integrate Gitlab
    "gitlab_user": "MyUserName", # Username
    "gitlab_repo": "MyDoc", # Repo name
    "gitlab_version": "master", # Version
    "conf_py_path": "/source/", # Path in the checkout to the docs root
}

They can be used like this:

{% if display_gitlab %}
    <a href="https://{{ gitlab_host|default("gitlab.com") }}/
    {{ gitlab_user }}/{{ gitlab_repo }}/blob/{{ gitlab_version }}
    {{ conf_py_path }}{{ pagename }}{{ suffix }}" class="fa fa-gitlab">
    Edit on GitLab</a>
{% endif %}

Additional variables¶

  • 'pagename' - Sphinx variable representing the name of the page you’re on.

Next
How-to guides: security and access
Previous
How to add custom CSS or JavaScript to Sphinx documentation
Copyright © Read the Docs, Inc & contributors
Made with Sphinx and @pradyunsg's Furo
On this page
  • Adding “Edit Source” links on your Sphinx theme
    • GitHub
    • Bitbucket
    • Gitlab
    • Additional variables