mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add styleesheet class
To keep compatibility with old themes, an instance of stylesheet behaves as its filename (refs: #1767).
This commit is contained in:
parent
b03b515556
commit
e6f8cd6c78
@ -738,15 +738,15 @@ class Sphinx(object):
|
||||
def add_stylesheet(self, filename, alternate=False, title=None):
|
||||
# type: (unicode, bool, unicode) -> None
|
||||
logger.debug('[app] adding stylesheet: %r', filename)
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||
props = {'rel': 'stylesheet',
|
||||
'filename': filename,
|
||||
'title': title} # type: Dict[unicode, unicode]
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder, Stylesheet
|
||||
if '://' not in filename:
|
||||
props['filename'] = posixpath.join('_static', filename)
|
||||
filename = posixpath.join('_static', filename)
|
||||
if alternate:
|
||||
props['rel'] = 'alternate stylesheet'
|
||||
StandaloneHTMLBuilder.css_files.append(props)
|
||||
rel = u'alternate stylesheet'
|
||||
else:
|
||||
rel = u'stylesheet'
|
||||
css = Stylesheet(filename, title, rel) # type: ignore
|
||||
StandaloneHTMLBuilder.css_files.append(css)
|
||||
|
||||
def add_latex_package(self, packagename, options=None):
|
||||
# type: (unicode, unicode) -> None
|
||||
|
@ -86,6 +86,23 @@ def get_stable_hash(obj):
|
||||
return md5(text_type(obj).encode('utf8')).hexdigest()
|
||||
|
||||
|
||||
class Stylesheet(text_type):
|
||||
"""The metadata of stylesheet.
|
||||
|
||||
To keep compatibility with old themes, an instance of stylesheet behaves as
|
||||
its filename (str).
|
||||
"""
|
||||
|
||||
def __new__(cls, filename, title, rel):
|
||||
# type: (unicode, unicode, unicode) -> None
|
||||
self = text_type.__new__(cls, filename) # type: ignore
|
||||
self.filename = filename
|
||||
self.title = title
|
||||
self.rel = rel
|
||||
|
||||
return self
|
||||
|
||||
|
||||
class StandaloneHTMLBuilder(Builder):
|
||||
"""
|
||||
Builds standalone HTML docs.
|
||||
|
Loading…
Reference in New Issue
Block a user