Logo

🚀 Tutorials

  • Read the Docs tutorial
  • Getting started with Sphinx
  • Getting started with MkDocs
  • Importing your documentation
  • Configuration file tutorial
  • Example projects

💡 Explanation

  • Choosing between our two platforms
  • Continuous Documentation Deployment
  • Understanding offline formats
  • Understanding environment variables
  • Subprojects: host multiple projects on a single domain
  • Localization of documentation
  • Deep dive into Read the Docs
  • Methodology and best practice

🪄 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

  • Feature reference
  • Configuration file v2 (.readthedocs.yaml)
  • Build process overview
  • Build process customization
  • Search query syntax
  • Frequently asked questions
  • Public API
  • 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.