diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index c0767a3..b7414e8 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -17,8 +17,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- python-version: [3.6, 3.7, 3.8]
- sphinx: [">=2,<3", ">=3,<4", "==4.0.0b1"]
+ python-version: [3.6, 3.7, 3.8, 3.9]
+ sphinx: [">=2,<3", ">=3,<4", ">=4,<5"]
+ pygments: ["==2.8.0", "==2.9.0", "==2.10.0"]
steps:
- uses: actions/checkout@v2
@@ -30,6 +31,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install "sphinx${{ matrix.sphinx }}"
+ pip install "pygments${{ matrix.pygments }}"
pip install .[testing]
- name: Run pytest
run: |
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 04e8cdf..52cea92 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,7 +1,7 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
- rev: v4.0.1
+ rev: v4.1.0
hooks:
- id: check-json
- id: check-yaml
@@ -11,17 +11,17 @@ repos:
".xml"
- repo: https://github.com/mgedmin/check-manifest
- rev: "0.46"
+ rev: "0.47"
hooks:
- id: check-manifest
- repo: https://github.com/psf/black
- rev: 21.7b0
+ rev: 22.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/pylint
- rev: v2.9.5
+ rev: v2.12.2
hooks:
- id: pylint
args:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7bca2e5..5ad7615 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,17 @@
# Change Log
+## 3.3.0 - 2022-03-09
+
+### Added
+
+* Testing for Python 3.9 and a few pygments versions
+* Dark theme selectors
+
+### Changed
+
+* Bumped docutils dependency to 0.17
+* Remaining string formatting to use f-strings
+
## 3.2.0 - 2021-06-11
### Fixed
diff --git a/setup.py b/setup.py
index d5af1f0..cb60110 100755
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,7 @@ def get_version():
url="https://github.com/executablebooks/sphinx-tabs",
license="MIT",
python_requires="~=3.6",
- install_requires=["sphinx>=2,<5", "pygments", "docutils~=0.16.0"],
+ install_requires=["sphinx>=2,<5", "pygments", "docutils~=0.17.0"],
extras_require={
"testing": [
"coverage",
diff --git a/sphinx_tabs/__init__.py b/sphinx_tabs/__init__.py
index 0327147..5833c51 100644
--- a/sphinx_tabs/__init__.py
+++ b/sphinx_tabs/__init__.py
@@ -1,3 +1,3 @@
-__version__ = "3.2.0"
+__version__ = "3.3.0"
__import__("pkg_resources").declare_namespace(__name__)
diff --git a/sphinx_tabs/static/tabs.css b/sphinx_tabs/static/tabs.css
index c74e895..02eaeb4 100644
--- a/sphinx_tabs/static/tabs.css
+++ b/sphinx_tabs/static/tabs.css
@@ -51,3 +51,50 @@
.sphinx-tab img {
margin-bottom: 24 px;
}
+
+/* Dark theme preference styling */
+
+@media (prefers-color-scheme: dark) {
+ body:not([data-theme="light"]) .sphinx-tabs-panel {
+ color: white;
+ background-color: rgb(50, 50, 50);
+ }
+
+ body:not([data-theme="light"]) .sphinx-tabs-tab {
+ color: white;
+ font-size: 16px;
+ font-weight: 400;
+ background-color: rgba(255, 255, 255, 0.05);
+ }
+
+ body:not([data-theme="light"]) .sphinx-tabs-tab[aria-selected="true"] {
+ font-weight: 700;
+ border: 1px solid #a0b3bf;
+ border-bottom: 1px solid rgb(50, 50, 50);
+ margin: -1px;
+ background-color: rgb(50, 50, 50);
+ }
+}
+
+/* Explicit dark theme styling */
+
+body[data-theme="dark"] .sphinx-tabs-panel {
+ color: white;
+ background-color: rgb(50, 50, 50);
+}
+
+body[data-theme="dark"] .sphinx-tabs-tab {
+ color: white;
+ font-size: 16px;
+ font-weight: 400;
+ border: 1px solid rgba(255, 255, 255, 0.15);
+ background-color: rgba(255, 255, 255, 0.05);
+}
+
+body[data-theme="dark"] .sphinx-tabs-tab[aria-selected="true"] {
+ font-weight: 700;
+ border: 1px solid #a0b3bf;
+ border-bottom: 2px solid rgb(50, 50, 50);
+ margin: -1px;
+ background-color: rgb(50, 50, 50);
+}
diff --git a/sphinx_tabs/tabs.py b/sphinx_tabs/tabs.py
index 2bd52ef..e99c500 100644
--- a/sphinx_tabs/tabs.py
+++ b/sphinx_tabs/tabs.py
@@ -91,7 +91,7 @@ def run(self):
self.env.temp_data["tabs_stack"] = []
tabs_id = self.env.temp_data["next_tabs_id"]
- tabs_key = "tabs_%d" % tabs_id
+ tabs_key = f"tabs_{tabs_id}"
self.env.temp_data["next_tabs_id"] += 1
self.env.temp_data["tabs_stack"].append(tabs_id)
@@ -141,7 +141,7 @@ def run(self):
self.assert_has_content()
tabs_id = self.env.temp_data["tabs_stack"][-1]
- tabs_key = "tabs_%d" % tabs_id
+ tabs_key = f"tabs_{tabs_id}"
include_tabs_id_in_data_tab = False
if self.tab_id is None:
@@ -160,13 +160,13 @@ def run(self):
i = 1
while tab_id in self.env.temp_data[tabs_key]["tab_ids"]:
- tab_id = "%s-%d" % (tab_id, i)
+ tab_id = f"{tab_id}-{i}"
i += 1
self.env.temp_data[tabs_key]["tab_ids"].append(tab_id)
data_tab = str(tab_id)
if include_tabs_id_in_data_tab:
- data_tab = "%d-%s" % (tabs_id, data_tab)
+ data_tab = f"{tabs_id}-{data_tab}"
self.env.temp_data[tabs_key]["tab_titles"].append((data_tab, tab_name))
@@ -254,7 +254,7 @@ def run(self):
tab_name = LEXER_MAP[self.arguments[0]]
except KeyError as invalid_lexer_error:
raise ValueError(
- "Lexer not implemented: {}".format(self.arguments[0])
+ f"Lexer not implemented: {self.arguments[0]}"
) from invalid_lexer_error
self.tab_classes.add("code-tab")
diff --git a/tests/conftest.py b/tests/conftest.py
index aea4aa0..6c15bd4 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -75,17 +75,19 @@ def regress_sphinx_app_output(file_regression, get_sphinx_app_output):
non-deterministic).
"""
- def read(
- app, buildername="html", filename="index.html", encoding="utf-8", replace=None
- ):
+ def read(app, buildername="html", filename="index.html", encoding="utf-8"):
content = get_sphinx_app_output(app, buildername, filename, encoding)
if buildername == "html":
soup = BeautifulSoup(content, "html.parser")
+
+ # Remove output from ``pygments``, so that test only compares HTML of surrounding tabs
+ for div in soup.find_all("div", {"class": "highlight"}):
+ div.decompose()
+
doc_div = soup.findAll("div", {"class": "documentwrapper"})[0]
doc = doc_div.prettify()
- for find, rep in (replace or {}).items():
- doc = text.replace(find, rep)
+
else:
doc = content
file_regression.check(
diff --git a/tests/roots/test-conditionalassets-policy/conf.py b/tests/roots/test-conditionalassets-policy/conf.py
new file mode 100644
index 0000000..1fc6dcb
--- /dev/null
+++ b/tests/roots/test-conditionalassets-policy/conf.py
@@ -0,0 +1,5 @@
+project = "sphinx-tabs test"
+master_doc = "index"
+source_suffix = ".rst"
+extensions = ["sphinx_tabs.tabs"]
+pygments_style = "sphinx"
diff --git a/tests/roots/test-conditionalassets-policy/index.rst b/tests/roots/test-conditionalassets-policy/index.rst
new file mode 100644
index 0000000..1d1ec6e
--- /dev/null
+++ b/tests/roots/test-conditionalassets-policy/index.rst
@@ -0,0 +1,130 @@
+.. toctree::
+
+ no_tabs1
+ no_tabs2
+
+Fruits
+========================================
+
+.. tabs::
+
+ .. tab:: Apples
+
+ Apples are green, or sometimes red.
+
+ .. tab:: Pears
+
+ Pears are green.
+
+ .. tab:: Oranges
+
+ Oranges are orange.
+
+Luminaries
+========================================
+
+.. tabs::
+
+ .. tab:: Sun
+
+ The sun is a star.
+
+ .. tab:: Moon
+
+ The moon is not a star.
+
+Code Tabs
+========================================
+
+.. tabs::
+
+ .. code-tab:: c
+
+ C Main Function
+
+ .. code-tab:: c++
+
+ C++ Main Function
+
+ .. code-tab:: py
+
+ Python Main Function
+
+ .. code-tab:: java
+
+ Java Main Function
+
+ .. code-tab:: julia
+
+ Julia Main Function
+
+ .. code-tab:: fortran
+
+ Fortran Main Function
+
+.. tabs::
+
+ .. code-tab:: c
+
+ int main(const int argc, const char **argv) {
+ return 0;
+ }
+
+ .. code-tab:: c++
+
+ int main(const int argc, const char **argv) {
+ return 0;
+ }
+
+ .. code-tab:: py
+
+ def main():
+ return
+
+ .. code-tab:: java
+
+ class Main {
+ public static void main(String[] args) {
+ }
+ }
+
+ .. code-tab:: julia
+
+ function main()
+ end
+
+ .. code-tab:: fortran
+
+ PROGRAM main
+ END PROGRAM main
+
+Group Tabs
+========================================
+
+.. tabs::
+
+ .. group-tab:: Linux
+
+ Linux Line 1
+
+ .. group-tab:: Mac OSX
+
+ Mac OSX Line 1
+
+ .. group-tab:: Windows
+
+ Windows Line 1
+
+.. tabs::
+
+ .. group-tab:: Linux
+
+ Linux Line 2
+
+ .. group-tab:: Mac OSX
+
+ Mac OSX Line 2
+
+ .. group-tab:: Windows
+
+ Windows Line 2
diff --git a/tests/roots/test-conditionalassets-policy/no_tabs1.rst b/tests/roots/test-conditionalassets-policy/no_tabs1.rst
new file mode 100644
index 0000000..291ccfa
--- /dev/null
+++ b/tests/roots/test-conditionalassets-policy/no_tabs1.rst
@@ -0,0 +1,4 @@
+Another page without tabs
+========================================
+
+No tabs to see here
diff --git a/tests/roots/test-conditionalassets-policy/no_tabs2.rst b/tests/roots/test-conditionalassets-policy/no_tabs2.rst
new file mode 100644
index 0000000..99ef57d
--- /dev/null
+++ b/tests/roots/test-conditionalassets-policy/no_tabs2.rst
@@ -0,0 +1,4 @@
+And another page without tabs
+========================================
+
+No tabs to see here either
diff --git a/tests/test_build.py b/tests/test_build.py
index ee01aa9..a44a9ef 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -27,7 +27,7 @@ def test_conditional_assets(app, docname, check_asset_links):
@pytest.mark.noautobuild
@pytest.mark.parametrize("docname", ["index", "no_tabs1", "no_tabs2"])
-@pytest.mark.sphinx(testroot="conditionalassets")
+@pytest.mark.sphinx(testroot="conditionalassets-policy")
@pytest.mark.skipif(
sphinx.version_info[:2] < (4, 1), reason="Test uses Sphinx 4.1 config"
)
@@ -64,9 +64,9 @@ def test_other_with_assets(app, check_asset_links):
@pytest.mark.sphinx(testroot="linenos")
@pytest.mark.skipif(
- sphinx.version_info[:2] <= (4, 0), reason="Test uses Sphinx 4 code blocks"
+ sphinx.version_info[:2] < (4, 0), reason="Test uses Sphinx 4 code blocks"
)
-def test_other_With_assets_new_style(app, check_asset_links):
+def test_other_with_assets_new_style(app, check_asset_links):
check_asset_links(app)
diff --git a/tests/test_build/test_conditional_assets_html_assets_policy_index_.html b/tests/test_build/test_conditional_assets_html_assets_policy_index_.html
new file mode 100644
index 0000000..1032d5e
--- /dev/null
+++ b/tests/test_build/test_conditional_assets_html_assets_policy_index_.html
@@ -0,0 +1,248 @@
+
+
+
+
+
+
+ Fruits
+
+
+
+
+
+
+
+
+
+
+ Apples are green, or sometimes red.
+
+
+
+
+
+ Oranges are orange.
+
+
+
+
+
+
+ Luminaries
+
+
+
+
+
+
+
+
+
+ The sun is a star.
+
+
+
+
+ The moon is not a star.
+
+
+
+
+
+
+ Code Tabs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Group Tabs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/test_build/test_conditional_assets_html_assets_policy_index_.xml b/tests/test_build/test_conditional_assets_html_assets_policy_index_.xml
new file mode 100644
index 0000000..7fe4f8f
--- /dev/null
+++ b/tests/test_build/test_conditional_assets_html_assets_policy_index_.xml
@@ -0,0 +1,152 @@
+
+
+
+
+
+ Fruits
+
+
+