Skip to main content
Ctrl+K
⚠️The latest release refactored our HTML, so double-check your custom CSS rules!⚠️
Logo image
  • Executable Books
  • PyPI

Topic Areas

  • Get started
  • Content and formatting
    • Special content blocks
    • PyData Theme Elements
    • Jupyter notebooks
    • Launch buttons for interactivity
  • Layout and major sections
    • Primary sidebar and navigation
    • Secondary sidebar and table of contents
    • Header and navbar
    • Content footer
    • Page footer
    • Announcement banners
  • Component customization
    • Logo and branding
    • Icon links and badges
    • Add a download page button
    • Buttons that link to source files
    • Add your own CSS rules
  • Reference of theme options
  • Contributing guide
    • Set up your development workflow
    • Architecture of the repository
    • Style and design
    • Testing infrastructure
    • Releases and version numbers
    • Translation workflow
    • Creating sub-themes
  • Changelog

Example pages

  • Kitchen Sink
    • Admonitions
    • API documentation
    • Blocks
    • Generic items
    • Images & Figures
    • Lists
    • Really Long Page Title because we should test sidebar wrapping
    • Structural Elements
    • Tables
    • Typography
  • Theme-specific elements
  • Sphinx extension styles
  • Jupyter notebooks
  • Thebe
  • Reference for Blog
  • NumPy docstrings
  • Comments
  • Show source
  • Suggest edit
  • Open issue
  • .md

Buttons that link to source files

Contents

  • Set your source repository
    • Manually specify the provider
  • Add a button to the page source
  • Add a button to suggest edits
  • Add a link to your repository
  • Add a button to open issues

Buttons that link to source files#

There are a collection of buttons that you can use to link back to your source repository. This lets users browse the repository, or take actions like suggest an edit or open an issue.

Set your source repository#

You need to define a source repository for this functionality to work. This is the online space where your code / documentation is hosted. To In each case, they require the following configuration to exist:

html_theme_options = {
    ...
    "repository_url": "https://{your-provider}/{org}/{repo}",
    ...
}

Three providers are supported:

  • GitHub: For example, https://github.com/executablebooks/sphinx-book-theme. This includes custom URLs for self-hosted GitHub.

  • GitLab: For example, https://gitlab.com/gitlab-org/gitlab. This includes custom URLs for self-hosted GitLab.

  • BitBucket: For example, https://opensource.ncsa.illinois.edu/bitbucket/scm/u3d/3dutilities.

In each case, we assume the final two URL items are the org/repo pair.

Manually specify the provider#

If your provider URL is more complex (e.g., if you’re self-hosting your provider), you can manually specify the provider with the following configuration:

html_theme_options = {
    ...
    "repository_provider": "gitlab"  # or "github", "bitbucket",
    "repository_url": "selfhostedgh.mycompany.org/user/repo",
    ...
}

Once this is provided, you may add source buttons by following the following sections.

Add a button to the page source#

Show the raw source of the page on the provider you’ve proivded. To add a button to the page source, first configure your source repository and then add:

html_theme_options = {
    ...
    "use_source_button": True,
    ...
}

Then configure the repository branch to use for your source. By default it is main, but if you’d like to change this, use the following configuration:

html_theme_options = {
    ...
    "repository_branch": "{your-branch}",
    ...
}

Finally, configure the relative path to your documentation. By default, this is the root of the repository, but if your documentation is hosted in a sub-folder, use the following configuration:

html_theme_options = {
    ...
    "path_to_docs": "{path-relative-to-site-root}",
    ...
}

Add a button to suggest edits#

Allow users to edit the page text directly on the provider and submit a pull request to update the documentation. To add a button to edit the page, first configure your source repository and then add:

html_theme_options = {
    ...
    "use_edit_page_button": True,
    ...
}

Then follow the branch and relative path instructions in the source file section.

Add a link to your repository#

To add a link to your repository, add the following configuration:

html_theme_options = {
    ...
    "use_repository_button": True,
    ...
}

Add a button to open issues#

To add a button to open an issue about the current page, use the following configuration:

html_theme_options = {
    ...
    "use_issues_button": True,
    ...
}

previous

Add a download page button

next

Add your own CSS rules

Contents
  • Set your source repository
    • Manually specify the provider
  • Add a button to the page source
  • Add a button to suggest edits
  • Add a link to your repository
  • Add a button to open issues

By the Executable Book Project

© Copyright 2023.

Last updated on Mar 31, 2023.