mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Allow setting 'rel' and 'title' attributes for stylesheets.
This commit is contained in:
@@ -280,7 +280,7 @@ package.
|
||||
|
||||
.. versionadded:: 0.5
|
||||
|
||||
.. method:: Sphinx.add_stylesheet(filename)
|
||||
.. method:: Sphinx.add_stylesheet(filename, rel=None, title=None)
|
||||
|
||||
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
|
||||
@@ -288,6 +288,10 @@ package.
|
||||
|
||||
.. versionadded:: 1.0
|
||||
|
||||
.. versionchanged:: 1.4
|
||||
Optional ``rel`` and/or ``title`` attributes can be supplied with the *rel*
|
||||
and *title* arguments.
|
||||
|
||||
.. method:: Sphinx.add_latex_package(packagename, options=None)
|
||||
|
||||
Add *packagename* to the list of packages that LaTeX source code will include.
|
||||
|
||||
@@ -202,8 +202,19 @@ Overriding works like this::
|
||||
|
||||
.. data:: css_files
|
||||
|
||||
Similar to :data:`script_files`, for CSS files.
|
||||
Similar to :data:`script_files`, for CSS files::
|
||||
|
||||
{% set css_files = css_files + ["_static/mystyle.css"] %}
|
||||
|
||||
.. versionchanged:: 1.4
|
||||
Optionally, ``rel`` and/or ``title`` attributes can be provided by supplying
|
||||
a Python dictionary, in which case the filename is given in the ``filename``
|
||||
key::
|
||||
|
||||
{% set css_files = css_files + [{"filename":"_static/mystyle.css", "rel":"stylesheet", "title":"Default"}] %}
|
||||
|
||||
The default is no title and ``rel='stylesheet'``, but if only ``title``
|
||||
is given, the default is ``rel='alternate stylesheet'``.
|
||||
|
||||
Helper Functions
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -681,14 +681,17 @@ class Sphinx(object):
|
||||
StandaloneHTMLBuilder.script_files.append(
|
||||
posixpath.join('_static', filename))
|
||||
|
||||
def add_stylesheet(self, filename):
|
||||
def add_stylesheet(self, filename, rel=None, title=None):
|
||||
self.debug('[app] adding stylesheet: %r', filename)
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||
item = {}
|
||||
if rel is not None: item['rel'] = rel
|
||||
if title is not None: item['title'] = title
|
||||
if '://' in filename:
|
||||
StandaloneHTMLBuilder.css_files.append(filename)
|
||||
item['filename'] = filename
|
||||
else:
|
||||
StandaloneHTMLBuilder.css_files.append(
|
||||
posixpath.join('_static', filename))
|
||||
item['filename'] = posixpath.join('_static', filename)
|
||||
StandaloneHTMLBuilder.css_files.append(item)
|
||||
|
||||
def add_latex_package(self, packagename, options=None):
|
||||
self.debug('[app] adding latex package: %r', packagename)
|
||||
|
||||
@@ -103,7 +103,25 @@
|
||||
<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(cssfile, 1) }}" type="text/css" />
|
||||
{%- if cssfile.filename is defined %}
|
||||
{%- set filename = cssfile.filename %}
|
||||
{%- else %}
|
||||
{%- set filename = cssfile %}
|
||||
{%- endif %}
|
||||
{%- if cssfile.rel is defined %}
|
||||
{%- set rel = cssfile.rel %}
|
||||
{%- endif %}
|
||||
{%- if cssfile.title is defined and cssfile.title is string %}
|
||||
{%- if cssfile.rel is not defined %}
|
||||
{%- set rel = "alternate stylesheet" %}
|
||||
{%- endif %}
|
||||
<link rel="{{ rel }}" href="{{ pathto(filename, 1) }}" type="text/css" title="{{ cssfile.title }}" />
|
||||
{%- else %}
|
||||
{%- if cssfile.rel is not defined %}
|
||||
{%- set rel = "stylesheet" %}
|
||||
{%- endif %}
|
||||
<link rel="{{ rel }}" href="{{ pathto(filename, 1) }}" type="text/css" />
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{%- endmacro %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user