diff --git a/sphinx/application.py b/sphinx/application.py index 80c96d280..6f1418b2f 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -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 diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 7bfce0ad6..7c9bc8b62 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -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.