Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying multiple CSS files in themes #10465

Merged
merged 3 commits into from Jul 17, 2022

Conversation

tk0miya
Copy link
Member

@tk0miya tk0miya commented May 22, 2022

Feature or Bugfix

  • Feature

Purpose

@tk0miya tk0miya added type:enhancement enhance or introduce a new feature html theme labels May 22, 2022
@tk0miya tk0miya added this to the 5.1.0 milestone May 22, 2022
@mgeier
Copy link
Contributor

mgeier commented May 22, 2022

Thanks @tk0miya, this works great!

Since html_style can be used to overwrite this, wouldn't it make sense to extend html_style as well to accept a list of themes (in addition to a single string)?

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also remove the private _get_style_filename method if it is no longer used.

A

Comment on lines 275 to 282
def get_style_filenames(self) -> str:
if self.config.html_style is not None:
return [self.config.html_style]
elif self.theme:
stylesheet = self.theme.get_config('theme', 'stylesheet')
return [s.strip() for s in stylesheet.split(',')]
else:
return ['default.css']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_style_filenames(self) -> str:
if self.config.html_style is not None:
return [self.config.html_style]
elif self.theme:
stylesheet = self.theme.get_config('theme', 'stylesheet')
return [s.strip() for s in stylesheet.split(',')]
else:
return ['default.css']
def _get_style_filenames(self) -> Iterator[str]:
if isinstance(self.config.html_style, str):
yield self.config.html_style
elif self.config.html_style is not None:
yield from self.config.html_style
elif self.theme:
stylesheet = self.theme.get_config('theme', 'stylesheet')
yield from (s.strip() for s in stylesheet.split(', '))
else:
yield 'default.css'

@@ -309,7 +318,9 @@ def init_highlighter(self) -> None:
def init_css_files(self) -> None:
self.css_files = []
self.add_css_file('pygments.css', priority=200)
self.add_css_file(self._get_style_filename(), priority=200)

for filename in self.get_style_filenames():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for filename in self.get_style_filenames():
for filename in self._get_style_filenames():

CHANGES Outdated
Comment on lines 16 to 17
* #10444: html theme: Allow to specify multiple CSS files via ``stylesheet``
setting on ``theme.conf``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* #10444: html theme: Allow to specify multiple CSS files via ``stylesheet``
setting on ``theme.conf``
* #10444: html theme: Allow specifying multiple CSS files through the ``stylesheet``
setting in ``theme.conf`` or by setting ``html_style`` to an iterable of strings.

# Conflicts:
#	doc/templating.rst
#	sphinx/builders/html/__init__.py
#	tests/test_build_html.py
@AA-Turner AA-Turner changed the title Close #10444: html theme: Allow to specify multiple CSS files via "stylesheet" setting Allow specifying multiple CSS files via the "stylesheet" setting Jul 17, 2022
@AA-Turner AA-Turner changed the title Allow specifying multiple CSS files via the "stylesheet" setting Allow specifying multiple CSS files in themes Jul 17, 2022
@AA-Turner AA-Turner merged commit e7fc03b into sphinx-doc:5.x Jul 17, 2022
@tk0miya tk0miya deleted the 10444_multiple_theme_stylesheets branch July 18, 2022 04:00
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
html theme type:enhancement enhance or introduce a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load several css files in theme.conf
3 participants