Giter VIP home page Giter VIP logo

sphinx-bootstrap-theme's Introduction

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. This project uses tox for development, once you have tox installed (e.g., pip install tox), change directories to the sphinx-bootstrap-theme top-level directory.

  • Building documentation: tox -e docs
  • Validate html links in documentation: tox -e linkcheck
  • Validate the code style: tox -e lint

The encouraged way to develop with this package is to use a development server. Changes made to files local in the repository will require rebuilding the demo website, and using the development server will automate this process.

  1. In your terminal, execute tox -e server from the top level directory. By default, this runs on port 8000. If this port is in use, a pass-through argument to the underlying sphinx-autobuild tool is required such as tox -e server -- -p 8080. The -- between server and -p are required, that signals the end of the arguments to tox and everything after gets fed to sphinx-autobuild.
  2. Open your browser of choice and visit http://127.0.0.1:8000/ to see the server.
  3. Make any intended edits to the files in this repository. After the server finishes rebuilding you can refresh your browser to see the updates.
  4. When finished, make sure to end the server from your terminal you ran tox -e server with by issuing ctrl+c.

Packaging

When a tag is pushed of the form vX.Y.Z (with the starting v), it will build the distribution using tox -e dist and upload to PyPI automatically. Before pushing a tag, using Test PyPI should be done. In addition to tox, install twine (pip install twine).

# Build the distribution locally.
$ tox -e dist

# Attempt uploading to Test PyPI
$ twine upload -r testpypi dist/*

Note

The file sphinx_bootstrap_theme/__init__.py has the version number that will be created. Make sure it matches the tag you are creating, once an upload goes up it cannot be overwritten. If in preparing a release you find an error and need to rebuild, simply increase the dev version in __init__.py and then rebuild and reupload. For example:

--- a/sphinx_bootstrap_theme/__init__.py
+++ b/sphinx_bootstrap_theme/__init__.py
@@ -1,7 +1,7 @@
 """Sphinx bootstrap theme."""
 import os

-__version__ = "0.8.0.dev0"
+__version__ = "0.8.0.dev1"

After verifying that everything appears as desired on Test PyPI at the project URL, one can also test the installation if desired: pip install --index-url https://test.pypi.org/simple/ sphinx-bootstrap-theme

Now that everything is validated, we are ready for release.

  1. Set the version number in sphinx_bootstrap_theme/__init__.py correctly. E.g., for release 0.8.0, set __version__ = "0.8.0" without the trailing dev qualifier.
  2. If desired, rebuild and upload to Test PyPI. Commit and push the changed version number. Tag this commit git tag v0.8.0 (note the leading v is required for the CI/CD), and git push --tags. This should initiate the official release and upload it to PyPI (see the files .github/workflows/{package,github_pages}.yaml for more).
  3. Now that the release is out, update the version number so that any users installing from source do not believe they have an official release. E.g., set __version__ = "0.8.1.dev0", commit and push this "dev version bump" online.

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.

sphinx-bootstrap-theme's People

Contributors

00-matt avatar cvrebert avatar danack avatar daveisfera avatar drewhutchison avatar fjfeijoo avatar grncdr avatar ivoire avatar karelv avatar kaycebasques avatar larsoner avatar masklinn avatar michilu avatar miketheman avatar mroswell avatar newgene avatar ppyv avatar russell avatar ryan-roemer avatar sccolbert avatar sheile avatar shiumachi avatar svenevs avatar timhoffm avatar torbjoernk avatar troeger avatar vedranmiletic avatar vitaut avatar vkoby avatar zyga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sphinx-bootstrap-theme's Issues

Code Style: Reconcile Sphinx inline code HTML output.

Multi-word inline code strings have weird spacing, because the currently rendered HTML ends up like:

<tt class="docutils literal">
  <code>fab</code>
  <code>style</code
</tt>

Solution: Just replace the tt element entirely with a code and .text() in the rest.

Document does not link to http-routingtable

When creating REST API docs, using the original theme together with sphinxcontrib-httpdomain, an index page called http-routingtable is generated, and the link appears. But with sphinx-bootstrap-theme, the link is not there, but http-routingtable.html is still generated.

sidebar top margin and width changes when content is scrolled

Hi, really loving sphinx-bootstrap-theme. Love that it supports bootstrap 3 and the nice looking bootswatch themes.

Not sure if my issue is related to the following but for reproducibility please note I am using bootstrap v3, bootswatch spacelab theme. I have also customized the top navbar as navbar-inverse and commented out everything except the classes navbar-brand, navbar-version, hidden-sm so that it only shows those 3 things in the navbar.

I have set html_sidebars = {'**':['globaltoc.html','searchbox.html']} so that the globaltoc and searchbox is always in the sidebar for all pages.

When at the top of the page the sidebar is div class = "bs-sidenav affix-top" and looks/acts the way it should. Both in full screen 1200 and when the browser window is narrowed to simulate responsiveness.

When I scroll the content down from top it switches to
div class = "bs-sidenav affix" and the css formatting changes such that the top margin of the sidebar moves down about 20px and narrows to the left by about 20px in full screen size. I can correct this by customizing the css so that .affix class has the same top margin and width as the default of .affix-top. I have to do this both for full screen and narrow screen and because it needs to be responsive I am using width: xx%. However it's not always a perfect match and shouldn't be necessary in the first place. Just a bandaid solution at this point. It would be nice if this could be fixed in this addon.

It might also be related to changing inheritance from the div class = col-md-3 above it.

Make sidebar manu depth configurable

Currently, sidebars display the full depth of heading levels. This would better be made configurable, possibly at different levels in different pages, or at least globally.

Allow CSS Overriding

At the moment any CSS files with conflicting rules added through the method recommended are overridden, because they are linked before bootstrap / bootswatch.

It would be nice to be able to actually override styles with CSS without having to add !important to everything, by allowing the custom CSS file added to come after the shpinx theming files.

Themes weren't working

The bootswatch themes weren't working on my machine (running ubuntu 13.04 with firefox):

For example,

'bootswatch_theme': "united",

To fix the problem I had to modify layout.html:

Adding http: before //netdna

Here's the diff between my layout.html and the version I got from pip:

6c6
<       'http://netdna.bootstrapcdn.com/bootswatch/' + bootstrap_version + '/' + theme_bootswatch_theme + '/bootstrap.min.css',

---
>       '//netdna.bootstrapcdn.com/bootswatch/' + bootstrap_version + '/' + theme_bootswatch_theme + '/bootstrap.min.css',
30c30
<       'http://netdna.bootstrapcdn.com/bootswatch/' + bootstrap_version + '/' + theme_bootswatch_theme + '/bootstrap.min.css'

---
>       '//netdna.bootstrapcdn.com/bootswatch/' + bootstrap_version + '/' + theme_bootswatch_theme + '/bootstrap.min.css'

Search locally doesn't work

Sphinx 1.2 added a workaround to allow searching locally (from file://). That fix included this change in search.html. The last part should be added to the search.html of this template.

Thanks!

{% block extrahead %}
  <script type="text/javascript">
    jQuery(function() { Search.loadIndex("{{ pathto('searchindex.js', 1) }}"); });
  </script>
  {# this is used when loading the search index using $.ajax fails,
     such as on Chrome for documents on localhost #}
  <script type="text/javascript" id="searchindexloader"></script>
  {{ super() }}
{% endblock %}

Using the 'Flaty' bootswatch theme breaks the entire page

Any other theme seems to work fine, but when I make my HTML docs with the flaty theme using the following code:

html_theme_options = {
    'bootswatch_theme': 'flaty',
    'bootstrap_version': '2'
}

The entire page breaks and no CSS is being rendered (JS however is still there because you can see the "ΒΆ" signs being present when you hover).

HTML inside of literal are lost

In bootstrap-sphinx.js_t docutils.literal will be overwritten and a <code> element is generated. But the element does only contain the text, not html of the original child. The sphinx-php produce api doc links that are embedded into a literal, which are broken with the bootstrap theme.

I fixed it by using the html instead of text: return $("<code />").html($(this).html());

Pre tags should use scroll bars when the display is small

Currently on a small device the pre tag will wrap text. This causes the line numbers to not line up with the correct line.

Bootstrap by default is causing the pre tags to act responsive.. Perhaps an alternative is to use horizontal scroll bars so the lines are still relevant and the code isn't distorted.

Downloads: Replace GitHub downloads.

GitHub has disabled downloads. Need a replacement for that installation method.

Probably add as a build step to gh-pages and download straight from there (or something).

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.

Support bootswatch while offline (no CDN)

This ticket is meant to start a dicussion on how to support bootswatch while offline. My goal is to get fully offline bootswatch theme so that those could be used in Debian/Ubuntu for certain documentation builds.

For Debian packages, depending on the CDN would be inappropriate.

There are a few factors to consider:

  1. How to track upstream bootswatch code:
  • Do we copy each release?
  • Do we use submodule and track the version to bundle?
  1. How do we release sphinx-bootstrap-theme?

  2. How to select offline vs CND.

My suggestions are to:

  1. Use a git submodule
  2. Craft appropriate MANIFEST.in and setup.py settings to release both normal and minified css and javascript
  3. Use a new theme: "cdn" defaulting to False

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?

Hidden TOCTree being included in "Site" Dropdown

The title says everything.

In my particular case I like to split documentation in multiple files in order to review and edit them easily.

But all the files must be included in a TOCTree so I created a hidden one to make the warnings disappear. But even hidden it's being included in the "Site" dropdown

Feature request: some styling to help separate footer from body content

I'm liking sphinx-boostrap-theme a lot: it's easy to use and for the most part produces very smart looking output. However, one small tweak I'd like to see is some way of inserting more visual difference between the footer content and body content on each page... either some styling difference, perhaps, or a thin rule of some kind?

Having it configurable would also be great, for those who like the way things look now.

search bar width?

How do I control search bar width? I fiddled with bootstrap css -- but can't make the one affecting the width of the search bar.

Copy/install only selected bootstrap/bootswatch version and style/theme variant

It would be better and more efficient if only the selected bootstrap/bootswatch version and the selected bootswatch variant would be installed/copied into the sphinx generated HTML directory tree.

This may require some "path-normalization" for page resources (CSS, JS, etc.) in the template and some logic that prevents sphinx from copying the whole theme.

In addition, it seems that only the "*.min.css" versions are really used by HTML page. If this is true, only these needed resources should be copied.

Search input overflows navigation bar.

Now that the navigation bar can have arbitrary extra links, the search bar tends to overflow in unsightly ways, e.g.:

screen shot 2013-09-05 at 4 08 02 am

Task: Figure out something "nicer" to do with this scenario.

Wrong selector for inline code styles to Bootstrap style.

Hi, first of all. Thanks for sharing this. I love it!

Second: i found a little misstake with the selector for inline code style.

Changing line 155 of static/bootstrap-sphinx.js_t from

if (!$(e).parent().hasClass("reference")) {

to

if (!$(e).children().hasClass("reference")) {

fixe this for me. Otherwise the selector removes the link to external reference.

Uninstall does not work

pip uninstall sphinx-bootstrap-theme
Can't uninstall 'sphinx-bootstrap-theme'. No files were found to uninstall.

Search Button Theming

Ryan

Small question - not sure if there is an answer. The search page (the one you get to once you have searched) has a button on it which is unaligned and not-bootstrap themed.

I tried to figure out how this page is created (without much success) and suspect that it is unthemable - which is a bit irritating.

Thoughts/suggestions/can it be done?

Gordon

Bootswatch theme not working in Firefox?

I'm trying to install the basic setup, and use the united theme. When I add the setting on conf.py, the page is not styled. Looking at the source, I see the correct-looking link tag:

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/3.0.0/united/bootstrap.min.css" type="text/css" />

When I click on the URL in the "View Source" window, I get a "File not found" error.

I can access the page just by going to this URL:

http://netdna.bootstrapcdn.com/bootswatch/3.0.0/united/bootstrap.min.css

Bootstrap like table

Hi,

Thank you and congrats for the really nice work you've done !!

Shoft request/issue: would it be possible to use bootstrap style for tables generated by sphinx ?

Best regards,
Gilles

Questions originally posted in LooseBits.com

Hi,

This is is how I would like to structure the Main Page and these are the source files I have now.

How can I link entries of main TOCTree to other pages? I tried to use :ref: in some of them but they appear written in pink (as a reference is expected to be).

Visually it is correct but the Site dropdown is a total mess because I did not follow the spec I saw in your Django Documentation.

Based on it, I know where I'm using an H2 should be the first level of a UL, in order to add another... "dimension" in Site dropdown.

But I could not style this first level as a Heading or even insert a RAW HTML on it, even RAW HTML is considered by DOCUtils a bad practice.

Is it possible to build the main TOCTree only with children TOCTrees instead of using the sections and subsections concept?

If you look at this source file you can see a workaround I did in order to bypass this problem.

In this example, Interface, Abstract and Exception are important items and because of this they are marked with H2, but they're not so important to be part of the main TOCTree.

It would be great to have the ability to build the main TOCTree only with children TOCTrees so we could use the sections' and subsections' concept as they were originally designed without "dirtying" the TOCTree.

Plus, I guess, there is the advantage of fix the previous issue since it's possible to customize TOCTree links without reference them.

Is it possible to build the dropdown menu "Site" from multiples small TOCTrees?

Most of this question was merged with previous question but as an complement, there is the issue of for Next Chapter element (expected, but not desirable).

I know this is being caused because of the current structure I have but, if you manage to fix them, I think this would be automatically fixed

Can I hide the link "Source", like you did in your Django demonstration?

Solved as answered in Disqus comment. Just for the record and future reference, it's just use a unexpected value for source_link_position theme option.

And finally, can I translate the texts? My documentation is not primarily written in English

This doesn't need explanation, does it? ^^

Use Absolute URL instead of Relative URL

Hi @ryan-roemer,

Before I can post all the questions I did in your blog post I would like to know if I can change the relative URL's used to define CSS/JS paths to absolutes, so they can work in GitHub Pages too.

I already did the most "complicated" part, hosting the files here and setting up a Page but the CSS files (and probably JS too) are not being loaded.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.