Georg Brandl avatar Georg Brandl committed 5a9ce7c

#200: Added ``Sphinx.add_stylesheet()``.

Comments (0)

Files changed (5)

 Release 1.0 (in development)
 ============================
 
+* #200: Added ``Sphinx.add_stylesheet()``.
+
 * Added ``titlesonly`` option to ``toctree`` directive.
 
 * Removed the deprecated ``sphinx.builder`` module.

doc/ext/appapi.rst

 
    .. versionadded:: 0.5
 
+.. method:: Sphinx.add_stylesheet(filename)
+
+   Add *filename* to the list of CSS files that the default HTML template will
+   include.  Like for :meth:`add_javascript`, the filename must be relative to
+   the HTML static path.
+
+   .. versionadded:: 1.0
+
 .. method:: Sphinx.add_lexer(alias, lexer)
 
    Use *lexer*, which must be an instance of a Pygments lexer class, to

sphinx/application.py

         StandaloneHTMLBuilder.script_files.append(
             posixpath.join('_static', filename))
 
+    def add_stylesheet(self, filename):
+        from sphinx.builders.html import StandaloneHTMLBuilder
+        StandaloneHTMLBuilder.css_files.append(
+            posixpath.join('_static', filename))
+
     def add_lexer(self, alias, lexer):
         from sphinx.highlighting import lexers
         if lexers is None:

sphinx/builders/html.py

 
     # This is a class attribute because it is mutated by Sphinx.add_javascript.
     script_files = ['_static/jquery.js', '_static/doctools.js']
+    # Dito for this one.
+    css_files = []
 
     # cached publisher object for snippets
     _publisher = None
             show_source = self.config.html_show_sourcelink,
             file_suffix = self.out_suffix,
             script_files = self.script_files,
+            css_files = self.css_files,
             sphinx_version = __version__,
             style = stylename,
             rellinks = rellinks,

sphinx/themes/basic/layout.html

     <title>{{ title|striptags }}{{ titlesuffix }}</title>
     <link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
     <link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
+    {%- for cssfile in css_files %}
+    <link rel="stylesheet" href="{{ pathto('_static/' + cssfile, 1) }}" type="text/css" />
+    {%- endfor %}
     {%- if not embedded %}
     <script type="text/javascript">
       var DOCUMENTATION_OPTIONS = {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.