Skip to content

Commit 54776a3

Browse files
dgarcia360foster999
authored andcommitted
👌 IMPROVE: Add sphinx option to disable css from loading
Remove unused pylint
1 parent 69f31ff commit 54776a3

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

‎docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Custom lexers that have been loaded in the sphinx `conf.py` can be used with `co
4242
def setup(app):
4343
app.add_lexer('alias', MyCustomLexer())
4444
45+
By default, the extension loads predefined CSS styles for tabs. To disable the CSS from loading, add the following to your `conf.py`:
46+
47+
.. code-block:: python
48+
49+
sphinx_tabs_disable_css_loading = True
50+
4551
4652
Basic Tabs
4753
===========

‎sphinx_tabs/tabs.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ def found_tabs_directive(self):
291291
return self._found
292292

293293

294+
def update_config(app, config):
295+
"""Adds sphinx-tabs CSS and JS asset files"""
296+
for path in [Path(path) for path in FILES]:
297+
if not config.sphinx_tabs_disable_css_loading and path.suffix == ".css":
298+
if "add_css_file" in dir(app):
299+
app.add_css_file(path.as_posix())
300+
else:
301+
app.add_stylesheet(path.as_posix())
302+
if path.suffix == ".js":
303+
if "add_script_file" in dir(app):
304+
app.add_script_file(path.as_posix())
305+
else:
306+
app.add_js_file(path.as_posix())
307+
294308
# pylint: disable=unused-argument
295309
def update_context(app, pagename, templatename, context, doctree):
296310
"""Remove sphinx-tabs CSS and JS asset files if not used in a page"""
@@ -318,6 +332,7 @@ def update_context(app, pagename, templatename, context, doctree):
318332
def setup(app):
319333
"""Set up the plugin"""
320334
app.add_config_value("sphinx_tabs_valid_builders", [], "")
335+
app.add_config_value("sphinx_tabs_disable_css_loading", False, "html", [bool])
321336
app.add_config_value("sphinx_tabs_disable_tab_closing", False, "html", [bool])
322337
app.add_node(SphinxTabsContainer, html=(visit, depart))
323338
app.add_node(SphinxTabsPanel, html=(visit, depart))
@@ -332,17 +347,7 @@ def setup(app):
332347
"builder-inited",
333348
(lambda app: app.config.html_static_path.append(static_dir.as_posix())),
334349
)
335-
for path in [Path(path) for path in FILES]:
336-
if path.suffix == ".css":
337-
if "add_css_file" in dir(app):
338-
app.add_css_file(path.as_posix())
339-
else:
340-
app.add_stylesheet(path.as_posix())
341-
if path.suffix == ".js":
342-
if "add_script_file" in dir(app):
343-
app.add_script_file(path.as_posix())
344-
else:
345-
app.add_js_file(path.as_posix())
350+
app.connect("config-inited", update_config)
346351
app.connect("html-page-context", update_context)
347352

348353
return {

0 commit comments

Comments
 (0)