Logo

Getting started

  • Read the Docs tutorial
  • Choosing between our two platforms
  • Getting started with Sphinx
  • Getting started with MkDocs
  • Importing your documentation
  • Example projects

Project setup and configuration

  • Configuration file overview
  • Configuration file reference
  • 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
  • Canonical URLs
  • Content Delivery Network (CDN) and caching
  • sitemap.xml support
  • 404 Not Found pages
  • robots.txt support

Reading documentation

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

Maintaining projects

  • Redirects
  • Analytics for search and traffic
  • Security logs
  • Status badges
  • How to structure your documentation
  • Best practices for linking to your documentation
  • Security considerations for documentation pages

Business features

  • Business hosting
  • Organizations
  • Single Sign-On (SSO)
  • Sharing private documentation
  • How to manage your subscription

How-to guides

  • Project setup and configuration
  • Build process
  • Upgrading and maintaining projects
  • Content, themes and SEO
    • Search engine optimization (SEO) for documentation projects
    • Using traffic analytics
    • Using search analytics
    • Enabling canonical URLs
    • 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
    • Removing "Edit on ..." buttons from documentation
    • Adding "Edit Source" links on your Sphinx theme
      • GitHub
      • Bitbucket
      • Gitlab
      • Additional variables
  • Security and access
  • Account management
  • Best practice
  • Troubleshooting problems

Reference

  • Public REST API
  • Frequently asked questions
  • Changelog
  • About Read the Docs
  • Developer Documentation
Read the Docs user documentation
  • How-to guides: content, themes and SEO
  • Adding “Edit Source” links on your Sphinx theme
  • View page source

Adding “Edit Source” links on your Sphinx theme

Read the Docs injects some extra variables in the Sphinx html_context that are used by our Sphinx theme to display “edit source” links at the top of all pages. You can use these variables in your own Sphinx theme as well.

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.

Previous Next

© Copyright Read the Docs, Inc & contributors.

Built with Sphinx using a theme provided by Read the Docs.