Sphinx Bootstrap Theme

Overview

Sphinx Bootstrap Theme

This Sphinx theme integrates the Bootstrap CSS / JavaScript framework with various layout options, hierarchical menu navigation, and mobile-friendly responsive design. It is configurable, extensible, and can use any number of different Bootswatch CSS themes.

Introduction and Demos

The theme is introduced and discussed in the following posts:

Examples of the theme in use for some public projects:

The theme demo website also includes an examples page for some useful illustrations of getting Sphinx to play nicely with Bootstrap (also take a look at the examples source for the underlying reStructuredText).

Installation

Installation from PyPI is fairly straightforward:

  1. Install the package:

    $ pip install sphinx_bootstrap_theme
    
  2. Edit the "conf.py" configuration file to point to the bootstrap theme:

    # At the top.
    import sphinx_bootstrap_theme
    
    # ...
    
    # Activate the theme.
    html_theme = 'bootstrap'
    html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
    

Customization

The theme can be customized in varying ways (some a little more work than others).

Theme Options

The theme provides many built-in options that can be configured by editing your "conf.py" file:

# (Optional) Logo. Should be small enough to fit the navbar (ideally 24x24).
# Path should be relative to the ``_static`` files directory.
html_logo = "my_logo.png"

# Theme options are theme-specific and customize the look and feel of a
# theme further.
html_theme_options = {
    # Navigation bar title. (Default: ``project`` value)
    'navbar_title': "Demo",

    # Tab name for entire site. (Default: "Site")
    'navbar_site_name': "Site",

    # A list of tuples containing pages or urls to link to.
    # Valid tuples should be in the following forms:
    #    (name, page)                 # a link to a page
    #    (name, "/aa/bb", 1)          # a link to an arbitrary relative url
    #    (name, "http://example.com", True) # arbitrary absolute url
    # Note the "1" or "True" value above as the third argument to indicate
    # an arbitrary url.
    'navbar_links': [
        ("Examples", "examples"),
        ("Link", "http://example.com", True),
    ],

    # Render the next and previous page links in navbar. (Default: true)
    'navbar_sidebarrel': True,

    # Render the current pages TOC in the navbar. (Default: true)
    'navbar_pagenav': True,

    # Tab name for the current pages TOC. (Default: "Page")
    'navbar_pagenav_name': "Page",

    # Global TOC depth for "site" navbar tab. (Default: 1)
    # Switching to -1 shows all levels.
    'globaltoc_depth': 2,

    # Include hidden TOCs in Site navbar?
    #
    # Note: If this is "false", you cannot have mixed ``:hidden:`` and
    # non-hidden ``toctree`` directives in the same page, or else the build
    # will break.
    #
    # Values: "true" (default) or "false"
    'globaltoc_includehidden': "true",

    # HTML navbar class (Default: "navbar") to attach to <div> element.
    # For black navbar, do "navbar navbar-inverse"
    'navbar_class': "navbar navbar-inverse",

    # Fix navigation bar to top of page?
    # Values: "true" (default) or "false"
    'navbar_fixed_top': "true",

    # Location of link to source.
    # Options are "nav" (default), "footer" or anything else to exclude.
    'source_link_position': "nav",

    # Bootswatch (http://bootswatch.com/) theme.
    #
    # Options are nothing (default) or the name of a valid theme
    # such as "cosmo" or "sandstone".
    #
    # The set of valid themes depend on the version of Bootstrap
    # that's used (the next config option).
    #
    # Currently, the supported themes are:
    # - Bootstrap 2: https://bootswatch.com/2
    # - Bootstrap 3: https://bootswatch.com/3
    'bootswatch_theme': "united",

    # Choose Bootstrap version.
    # Values: "3" (default) or "2" (in quotes)
    'bootstrap_version': "3",
}

Note for the navigation bar title that if you don't specify a theme option of navbar_title that the "conf.py" project string will be used. We don't use the html_title or html_short_title values because by default those both contain version strings, which the navigation bar treats differently.

Bootstrap Versions

The theme supports Bootstrap v2.3.2 and v3.3.7 via the bootstrap_version theme option (of "2" or "3"). Some notes regarding version differences:

  • Bootstrap 3 has dropped support for sub-menus, so while supported by this theme, they will not show up in site or page menus.
  • Internally, "navbar.html" is the Sphinx template used for Bootstrap v3 and "navbar-2.html" is the template used for v2.
  • If you are unsure what to choose, choose Bootstrap 3. If you experience some form of compatibility issues, then try and use Bootstrap 2.

Extending "layout.html"

As a more "hands on" approach to customization, you can override any template in this Sphinx theme or any others. A good candidate for changes is "layout.html", which provides most of the look and feel. First, take a look at the "layout.html" file that the theme provides, and figure out what you need to override. As a side note, we have some theme-specific enhancements, such as the navbarextra template block for additional content in the navbar.

Then, create your own "_templates" directory and "layout.html" file (assuming you build from a "source" directory):

$ mkdir source/_templates
$ touch source/_templates/layout.html

Then, configure your "conf.py":

templates_path = ['_templates']

Finally, edit your override file "source/_templates/layout.html":

{# Import the theme's layout. #}
{% extends "!layout.html" %}

{# Add some extra stuff before and use existing with 'super()' call. #}
{% block footer %}
  <h2>My footer of awesomeness.</h2>
  {{ super() }}
{% endblock %}

Adding Custom CSS

Alternately, you could add your own custom static media directory with a CSS file to override a style, which in the demo would be something like:

$ mkdir source/_static
$ touch source/_static/my-styles.css

In the new file "source/_static/my-styles.css", add any appropriate styling, e.g. a bold background color:

footer {
  background-color: red;
}

Then, in "conf.py", edit this line:

html_static_path = ["_static"]

From there it depends on which version of Sphinx you are using:

Sphinx <= 1.5

You will need the override template "source/_templates/layout.html" file configured as above, but with the following code:

{# Import the theme's layout. #}
{% extends "!layout.html" %}

{# Custom CSS overrides #}
{% set css_files = css_files + ['_static/my-styles.css'] %}

Note

See Issue #159 for more information.

Sphinx >= 1.6.1

Add a setup function in "conf.py" with stylesheet paths added relative to the static path:

def setup(app):
    app.add_stylesheet("my-styles.css") # also can be a full URL
    # app.add_stylesheet("ANOTHER.css")
    # app.add_stylesheet("AND_ANOTHER.css")

Tip

Sphinx automatically calls your setup function defined in "conf.py" during the build process for you. There is no need to, nor should you, call this function directly in your code.

Theme Notes

Sphinx

The theme places the global TOC, local TOC, navigation (prev, next) and source links all in the top Bootstrap navigation bar, along with the Sphinx search bar on the left side.

The global (site-wide) table of contents is the "Site" navigation dropdown, which is a configurable level rendering of the toctree for the entire site. The local (page-level) table of contents is the "Page" navigation dropdown, which is a multi-level rendering of the current page's toc.

Bootstrap

The theme offers Bootstrap v2.x and v3.x, both of which rely on jQuery v.1.9.x. As the jQuery that Bootstrap wants can radically depart from the jQuery Sphinx internal libraries use, the library from this theme is integrated via noConflict() as $jqTheme.

You can override any static JS/CSS files by dropping different versions in your Sphinx "_static" directory.

Contributing

Contributions to this project are most welcome. Please make sure that the demo site builds cleanly, and looks like what you want. We suggest using pipenv to build this project:

$ cd sphinx-bootstrap-theme
$ pipenv install --dev

Before working in this project directory, do:

$ pipenv shell

Next, build the demo:

$ fab clean && fab demo

Then, view the site in the development server:

$ fab demo_server

Also, if you are adding a new type of styling or Sphinx or Bootstrap construct, please add a usage example to the "Examples" page.

Note: If you are in Python 3, Fabric isn't available, so we have a very rough Makefile in its place. Try:

$ make clean && make demo

Then, view the site in the development server:

$ make demo_server

Licenses

Sphinx Bootstrap Theme is licensed under the MIT license.

Bootstrap v2 is licensed under the Apache license 2.0.

Bootstrap v3.1.0+ is licensed under the MIT license.

Comments
  • MAINT: Updates for latest sphinx

    MAINT: Updates for latest sphinx

    Sphinx has updated table styling a bit (https://github.com/sphinx-doc/sphinx/issues/6170) and it exposed a bug where it expects the main content to be styled as body but it wasn't by sphinx-bootstrap-theme. Also Sphinx script_files += support is deprecated. So this PR:

    1. Adds body style to the main div.
    2. Changes script_files to just use <link rel="stylesheet" syntax instead.

    Fixes our builds, which on latest sphinx looked wrong with tables rendered like:

    Screenshot from 2019-03-11 16-57-44

    And with this PR the script warning is gone and renders like (if I add a .body { min-width: unset !important; max-width: unset !important; } to our custom CSS:

    Screen Shot 2019-03-19 at 15 21 55

    But I am no Sphinx / HTML / js expert, so let me know if this isn't the right approach! I wasn't entirely sure how to validate that everything is working properly and nothing broke, so it would be good to have another set of eyes on the output, too, so we don't break people's pipelines.

    opened by larsoner 17
  • Modern CI and Python Tooling

    Modern CI and Python Tooling

    Sorry for this falling off my radar. Per our original discussion goals:

    • [X] Create GitHub actions CI.
    • [X] Test changes to packaging via setup.py (cherry-picked relevant changes from @althonos, closes #203)
    • [X] Add placeholder tests for linting (to be added later)
      • Some linting is there. There's like no actual python code though haha.
      • The "test" is just running sphinx-build --version.
    • [X] Make sure that demo site builds in CI.
      • Warnings and nitpicky. Note: see changes to examples.rst, there seems to be a major problem with the sphinx javascript domain and linking parameters. Just switched to C++ instead...not our problem. AKA prefer nitpicky / warnings=error over sample js code.
    • [X] Make sure we have local demo-server.
    • [X] Push things to gh-pages branch only on tagged releases.
    • [X] Update contributing section of README to explain how to use the new tools.
    • [X] Remove old tooling such as fabfile, top-level makefile, and outdated section in README.
    • Fixes #216.

    CC: @jorisvandenbossche ref: #201

    opened by svenevs 16
  • Refresh sidebar for bootstrap 3.

    Refresh sidebar for bootstrap 3.

    This is an updated styling for the sidebar that seems to work better. It's been updated to be more like the sidebar on the bootstrap documentation site.

    I moved the searchbox html so that the configuration of the sidebar would be more like the sphinx documentation.

    Cheers, Russell

    opened by russell 14
  • Enable integration with Bootstrap apps

    Enable integration with Bootstrap apps

    Is there a way to embed this into a web app that uses Bootstrap as well?

    For example, an existing Bootstrap-based design might have an existing menubar with app functionality, but want to include a "Help" menu that points to Sphinx-generated docs that use this template. I think this means the documentation navigation would all have to be in a single (possible-hierarchical) menu that can be embedded in an existing app. Any thoughts?

    opened by felciano 14
  • pair of double quotes in theme.conf being read literally

    pair of double quotes in theme.conf being read literally

    The default theme.conf contains the line bootswatch_theme = "". When building a project with Sphinx 1.3a0 under Python 2.7.5, this works fine, but with Sphinx 1.3b2 under Python 3.4.2, this fails to generate a correct <link> tag: <link rel="stylesheet" href="_static/bootswatch-3.2.0/""/bootstrap.min.css" type="text/css" />

    Somehow the pair of quotes is no longer being read as a "False" value, causing layout.html to act as though a bootswatch theme was specified. The fix is easy enough: in the default theme.conf, just remove the quotes.

    opened by EricFromCanada 11
  • Add support for bootswatch.

    Add support for bootswatch.

    Bootswatch (http://bootswatch.com/) has a collection of themes for bootstrap. I would like to have support for selecting a bootswatch theme in html_theme_options.

    I have a working implementation of this but I would like to see if you are interested in having this upstream. The way I did this was to add all of the bootswatch themes in a subdirectory and patch layout.html to use it, defaulting to an empty, original, theme.

    opened by zyga 11
  • CSS conflict with Sphinx's basic theme

    CSS conflict with Sphinx's basic theme

    In a recent commit (relating to these issues and these pull requests), Sphinx added rules for "div.container" to basic.css, which overwrites rules in bootstrap.min.css. The most noticeable effect is extra padding appearing in the header above the title and search bar. Not sure if I'm better off asking the Sphinx maintainers to make their CSS more specific, so I thought I'd file it here first.

    opened by EricFromCanada 10
  • dropdown menu with its own TOC

    dropdown menu with its own TOC

    Hi,

    It is nice to see sphnix and bootstrap are combined together. Thanks.

    In current sphix-bootstrap-theme, there are Site and Page menus, and Page menu always shows the local TOC for current page. I would like to use several button menus and some menus have its own TOC (not from the current page). See a demo from bootstrap http://getbootstrap.com/examples/sticky-footer-navbar/. In this demo, the TOC in the dropdown menu is not the global TOC, or local TOC. Do you have any suggestion to generate a web page like this demo using sphinx-bootstrap-theme? Thanks.

    best, Jian Cheng

    opened by JianCheng 10
  • Switch to css imports rather than css_files hackery.

    Switch to css imports rather than css_files hackery.

    The theme uses css_files hackery, but that is deprecated in modern Sphinx and error prone because there are real object instances and not strings that now comprise css_files. See, e.g. #158

    This PR switches all of the conditionally-included CSS files into css @import url("NAME.css"); statements and just now has one root style sheet included the old fashioned way. Hopefully this is both backwards compatible with any previous Sphinx versions and works better as css_files goes off into deprecation sunset.

    Would appreciate folks pulling this down and kicking the tires!

    /cc @alexhagen @has2k1 @pcav

    opened by ryan-roemer 9
  • Sidebar scrolling

    Sidebar scrolling

    On this page (http://python-future.org/compatible_idioms.html) it's impossible to scroll the sidebar, which contains the table of contents for the page. It of course would be much easier to navigate a page such as this if the table of contents in the sidebar were scrollable. Even though the sidebar is long, the actual page is much longer!

    It seems that the problem is that the affix class is added to the #sidebar div. This isn't present in the HTML sources, so it must be added dynamically in JS.

    Is it possible to disable this?

    BTW: I'm surprised that nobody seems to have reported this issue before. Is my site the only one with a long sidebar?!

    bug confirmed 
    opened by edschofield 9
  • BUG: Fix for Sphinx 3.4+ search

    BUG: Fix for Sphinx 3.4+ search

    Our version of https://github.com/readthedocs/sphinx_rtd_theme/pull/1021 to fix issues due to https://github.com/sphinx-doc/sphinx/issues/8623, i.e., search.html not actually searching due to Uncaught ReferenceError: Stemmer is not defined in Sphinx 3.4+.

    Closes #214 Closes #220

    opened by larsoner 8
  • navbar_links supports menus

    navbar_links supports menus

    I did not test this with the demo site as I tested and develop this solution elsewhere but even if its not accepted then at least its out there so people can see how to change it if they want.

    opened by meisnate12 0
  • 0.8.0: tox is failing

    0.8.0: tox is failing

    I'm not sure what is wrong here. May I ask for some advice? Python 3.8.12, tox 3.24.4

    + /usr/bin/tox --skip-missing-interpreters
    GLOB sdist-make: /home/tkloczko/rpmbuild/BUILD/sphinx-bootstrap-theme-0.8.0/setup.py
    py create: /home/tkloczko/rpmbuild/BUILD/sphinx-bootstrap-theme-0.8.0/.tox/py
    ERROR: invocation failed (exit code 1), logfile: /home/tkloczko/rpmbuild/BUILD/sphinx-bootstrap-theme-0.8.0/.tox/py/log/py-0.log
    ================================================================================ log start =================================================================================
    RuntimeError: failed to build image wheel because:
    Traceback (most recent call last):
      File "/usr/lib/python3.8/site-packages/virtualenv/seed/embed/via_app_data/via_app_data.py", line 51, in _install
        key = Path(installer_class.__name__) / wheel.path.stem
    AttributeError: 'NoneType' object has no attribute 'path'
    
    
    ================================================================================= log end ==================================================================================
    ERROR: InvocationError for command /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python3 py (exited with code 1)
    lint create: /home/tkloczko/rpmbuild/BUILD/sphinx-bootstrap-theme-0.8.0/.tox/lint
    ERROR: invocation failed (exit code 1), logfile: /home/tkloczko/rpmbuild/BUILD/sphinx-bootstrap-theme-0.8.0/.tox/lint/log/lint-0.log
    ================================================================================ log start =================================================================================
    RuntimeError: failed to build image wheel because:
    Traceback (most recent call last):
      File "/usr/lib/python3.8/site-packages/virtualenv/seed/embed/via_app_data/via_app_data.py", line 51, in _install
        key = Path(installer_class.__name__) / wheel.path.stem
    AttributeError: 'NoneType' object has no attribute 'path'
    
    
    ================================================================================= log end ==================================================================================
    ERROR: InvocationError for command /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python3 lint (exited with code 1)
    _________________________________________________________________________________ summary __________________________________________________________________________________
    ERROR:   py: InvocationError for command /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python3 py (exited with code 1)
    ERROR:   lint: InvocationError for command /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python3 lint (exited with code 1)
    
    opened by kloczek 2
  • Docs: CONTRIBUTING.rst guide

    Docs: CONTRIBUTING.rst guide

    How to get up and running in a python dev environment for this project

    • [ ] Getting a python version (OS-specific, or maybe asdf)
    • [ ] Use pipenv or something?
    • [ ] How to fully install this project and run all checks.
    documentation 
    opened by ryan-roemer 0
  • Text above first heading is hidden

    Text above first heading is hidden

    When I use the sphinx boostrap theme, I want to put a line above the first heading that lists all the ancestors of the current section in order; i.e., the position of the current section in the tree. When I do this, the line is hidden by the navigation bar at the top of the page.

    opened by bradbell 0
  • Add overflow-wrap for sidebar

    Add overflow-wrap for sidebar

    By default, overflow is handled for words separated by space. This does not work if words are separated by other separators such as underscore or hyphen leading to sidebar headings and content overlap.

    opened by venkatsc 1
  • controlling autodoc output appearance

    controlling autodoc output appearance

    sorry this is again a question and not an issue, and again I'm not sure whether it's sphinx-bootstrap or sphinx or needs custom templates. I was just wondering whether I can control the visualization of the autodoc output, e.g. highlighting of the class/function, fontsize, spacing, etc.

    this is my doc: https://mluerig.github.io/phenopype/api.html#preprocessing

    doing something like this yellow ribbon and larger fontsize would help http://soft-matter.github.io/trackpy/v0.4.2/generated/trackpy.locate.html#trackpy.locate

    or a structure like in the sphinx doc, although I guess that's a whole theme https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html

    opened by mluerig 0
Owner
Ryan Roemer
Software geek, former patent attorney, & co-founder of @FormidableLabs. Curator of @SeaNode.
Ryan Roemer
Sphinx-performance - CLI tool to measure the build time of different, free configurable Sphinx-Projects

CLI tool to measure the build time of different, free configurable Sphinx-Projec

useblocks 11 Nov 25, 2022
Sphinx theme for readthedocs.org

Read the Docs Sphinx Theme This Sphinx theme was designed to provide a great reader experience for documentation users on both desktop and mobile devi

Read the Docs 4.3k Dec 31, 2022
Main repository for the Sphinx documentation builder

Sphinx Sphinx is a tool that makes it easy to create intelligent and beautiful documentation for Python projects (or other documents consisting of mul

null 5.1k Jan 2, 2023
A curated list of awesome tools for Sphinx Python Documentation Generator

Awesome Sphinx (Python Documentation Generator) A curated list of awesome extra libraries, software and resources for Sphinx (Python Documentation Gen

Hyunjun Kim 831 Dec 27, 2022
Main repository for the Sphinx documentation builder

Sphinx Sphinx is a tool that makes it easy to create intelligent and beautiful documentation for Python projects (or other documents consisting of mul

null 5.1k Jan 4, 2023
Numpy's Sphinx extensions

numpydoc -- Numpy's Sphinx extensions This package provides the numpydoc Sphinx extension for handling docstrings formatted according to the NumPy doc

NumPy 234 Dec 26, 2022
ReStructuredText and Sphinx bridge to Doxygen

Breathe Packagers: PGP signing key changes for Breathe >= v4.23.0. https://github.com/michaeljones/breathe/issues/591 This is an extension to reStruct

Michael Jones 643 Dec 31, 2022
Type hints support for the Sphinx autodoc extension

sphinx-autodoc-typehints This extension allows you to use Python 3 annotations for documenting acceptable argument types and return value types of fun

Alex Grönholm 462 Dec 29, 2022
Watch a Sphinx directory and rebuild the documentation when a change is detected. Also includes a livereload enabled web server.

sphinx-autobuild Rebuild Sphinx documentation on changes, with live-reload in the browser. Installation sphinx-autobuild is available on PyPI. It can

Executable Books 440 Jan 6, 2023
sphinx builder that outputs markdown files.

sphinx-markdown-builder sphinx builder that outputs markdown files Please ★ this repo if you found it useful ★ ★ ★ If you want frontmatter support ple

Clay Risser 144 Jan 6, 2023
A powerful Sphinx changelog-generating extension.

What is Releases? Releases is a Python (2.7, 3.4+) compatible Sphinx (1.8+) extension designed to help you keep a source control friendly, merge frien

Jeff Forcier 166 Dec 29, 2022
📖 Generate markdown API documentation from Google-style Python docstring. The lazy alternative to Sphinx.

lazydocs Generate markdown API documentation for Google-style Python docstring. Getting Started • Features • Documentation • Support • Contribution •

Machine Learning Tooling 118 Dec 31, 2022
Seamlessly integrate pydantic models in your Sphinx documentation.

Seamlessly integrate pydantic models in your Sphinx documentation.

Franz Wöllert 71 Dec 26, 2022
Speed up Sphinx builds by selectively removing toctrees from some pages

Remove toctrees from Sphinx pages Improve your Sphinx build time by selectively removing TocTree objects from pages. This is useful if your documentat

Executable Books 8 Jan 4, 2023
python package sphinx template

python-package-sphinx-template python-package-sphinx-template

Soumil Nitin Shah 2 Dec 26, 2022
epub2sphinx is a tool to convert epub files to ReST for Sphinx

epub2sphinx epub2sphinx is a tool to convert epub files to ReST for Sphinx. It uses Pandoc for converting HTML data inside epub files into ReST. It cr

Nihaal 8 Dec 15, 2022
A `:github:` role for Sphinx

sphinx-github-role A github role for Sphinx. Usage Basic usage MyST: :caption: index.md See {github}`astrojuanlu/sphinx-github-role#1`. reStructuredT

Juan Luis Cano Rodríguez 4 Nov 22, 2022
This is a template (starter kit) for writing Maturity Work with Sphinx / LaTeX at Collège du Sud

sphinx-tm-template Ce dépôt est un template de base utilisable pour écrire ton travail de maturité dans le séminaire d'informatique du Collège du Sud.

null 6 Dec 22, 2022
A Material Design theme for MkDocs

A Material Design theme for MkDocs Create a branded static site from a set of Markdown files to host the documentation of your Open Source or commerci

Martin Donath 12.3k Jan 4, 2023