From 3f5708a49d64c0cc62af43b3b002895565e6aba7 Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Thu, 5 Jan 2023 13:01:40 +0100 Subject: [PATCH 01/11] Remove JQuery and update versions --- .github/workflows/tests.yml | 4 +- README.md | 2 +- docs/index.md | 2 +- pyproject.toml | 31 ++--- src/sphinx_book_theme/assets/scripts/index.js | 43 +++---- .../assets/styles/abstracts/_variables.scss | 5 - .../styles/sections/_header-article.scss | 10 -- .../header_buttons/__init__.py | 7 +- .../header_buttons/launch.py | 2 - .../sphinx_book_theme/macros/buttons.html | 15 +-- .../sections/header-article.html | 4 +- tests/test_build/build__header-article.html | 18 +-- .../build__sidebar-primary__nav.html | 110 +++++++++--------- .../header__repo-buttons--all-off.html | 6 +- .../header__repo-buttons--all-on.html | 12 +- .../header__repo-buttons--custom-branch.html | 10 +- .../header__repo-buttons--one-on.html | 8 +- tests/test_build/test_header_launchbtns.html | 10 +- tests/test_build/test_topbar_launchbtns.html | 61 ---------- tox.ini | 6 +- 20 files changed, 131 insertions(+), 235 deletions(-) delete mode 100644 tests/test_build/test_topbar_launchbtns.html diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index afceaa862..3237b2320 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,11 +27,11 @@ jobs: matrix: os: [ubuntu-latest] python-version: [3.7, 3.8, 3.9] - sphinx: [">=4,<5", ">=5,<6"] + sphinx: [">=4,<5", ">=5,<6", ">=6, <7"] include: - os: windows-latest python-version: 3.9 - sphinx: ">=4,<5" + sphinx: ">=5,<6" - os: macos-latest python-version: 3.9 sphinx: ">=5,<6" diff --git a/README.md b/README.md index aae599b9e..cc24ca2be 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is a lightweight Sphinx theme designed to mimic the look-and-feel of an interactive book. It has the following primary features: -* **Bootstrap 4** +* **Bootstrap 5** for visual elements and functionality. * **Flexible content layout** that is inspired by beautiful online books, such as [the Edward Tufte CSS guide](https://edwardtufte.github.io/tufte-css/) diff --git a/docs/index.md b/docs/index.md index 31a597908..d22c5d7b9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -33,7 +33,7 @@ A Sphinx theme with a clean design, support for interactive content, and a moder [Launch buttons for online interactivity](launch) : For pages that are built with computational material, connect your site to an online BinderHub for interactive content. -[Bootstrap 4](https://getbootstrap.com/docs/4.0/getting-started/introduction/) +[Bootstrap 5](https://getbootstrap.com/docs/5.0/getting-started/introduction/) : To style visual elements and add functionality. International diff --git a/pyproject.toml b/pyproject.toml index a3ba6f39b..b129c6b12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,9 +22,8 @@ readme = "README.md" requires-python = ">=3.7" dependencies = [ - "sphinx>=4,<6", - "pydata-sphinx-theme~=0.12.0", - "pyyaml", + "sphinx>=4,<7", + "pydata-sphinx-theme@git+https://github.com/pydata/pydata-sphinx-theme#egg=main", ] license = { file = "LICENSE" } @@ -44,43 +43,37 @@ classifiers = [ [project.optional-dependencies] code_style = [ - "pre-commit>=2.7,<2.21" + "pre-commit" ] doc = [ - "ablog~=0.10.13", + "ablog", "ipywidgets", "folium", "numpy", "matplotlib", "numpydoc", - "myst-nb~=0.16.0", + "myst-nb", "nbclient", "pandas", "plotly", - "sphinx>=4.0,<6", "sphinx-design", "sphinx-examples", "sphinx-copybutton", "sphinx-tabs", - "sphinx-togglebutton>=0.2.1", - "sphinx-thebe>=0.1.1", - "sphinxcontrib-bibtex~=2.2", + "sphinx-togglebutton", + "sphinx-thebe", + "sphinxcontrib-bibtex", "sphinxcontrib-youtube", "sphinxext-opengraph", - # 8.7.0 broke the `ipython3` lexer in Sphinx so we want to avoid it - # remove this when 8.7.1 is released (and see below for another instance) - "ipython!=8.7.0", ] test = [ "beautifulsoup4>=4.6.1,<5", "coverage", - "myst-nb~=0.16.0", - "pytest~=7.1", - "pytest-cov>=3,<5", - "pytest-regressions>=2.0.1,<2.5.0", + "myst-nb", + "pytest", + "pytest-cov", + "pytest-regressions", "sphinx_thebe", - # 8.7.0 broke the `ipython3` lexer in Sphinx so we want to avoid it - "ipython!=8.7.0", ] [project.entry-points] diff --git a/src/sphinx_book_theme/assets/scripts/index.js b/src/sphinx_book_theme/assets/scripts/index.js index 3ebfda12c..1b4458b8a 100644 --- a/src/sphinx_book_theme/assets/scripts/index.js +++ b/src/sphinx_book_theme/assets/scripts/index.js @@ -49,19 +49,6 @@ var toggleFullScreen = () => { } }; -/** - * Called when the "print to PDF" button is clicked. - * This is a hack to prevent tooltips from showing up in the printed PDF. - */ -var printPdf = (el) => { - // Detach the tooltip text from DOM to hide in PDF - // and then reattach it for HTML - let tooltipID = $(el).attr("aria-describedby"); - let tooltipTextDiv = $("#" + tooltipID).detach(); - window.print(); - $("body").append(tooltipTextDiv); -}; - /** * Manage scrolling behavior. This is primarily two things: * @@ -97,9 +84,11 @@ var initTocHide = () => { // Hide the TOC if any margin content is displayed on the screen if (onScreenItems.length > 0) { - $("div.bd-sidebar-secondary").addClass("hide"); + document.querySelector("div.bd-sidebar-secondary").classList.add("hide"); } else { - $("div.bd-sidebar-secondary").removeClass("hide"); + document + .querySelector("div.bd-sidebar-secondary") + .classList.remove("hide"); } }; let manageScrolledClassOnBody = (entries, observer) => { @@ -152,10 +141,17 @@ var initTocHide = () => { * Activate Thebe with a custom button click. */ var initThebeSBT = () => { - var title = $("div.section h1")[0]; - if (!$(title).next().hasClass("thebe-launch-button")) { - $("").insertAfter($(title)); + var title = document.querySelector("section h1"); + var sibling = title.nextElementSibling; + // If the next element after the title isn't a thebe button, add one now. + // That way it is initiatlized when thebe is first-clicked and isn't re-added after. + if (!sibling.classList.contains("thebe-launch-button")) { + title.insertAdjacentHTML( + "afterend", + "", + ); } + // This function is provided by sphinx-thebe initThebe(); }; @@ -164,11 +160,11 @@ var initThebeSBT = () => { */ function addNoPrint() { - $("div.bd-sidebar-primary").addClass("noprint"); - $("div.bd-sidebar-secondary").addClass("noprint"); - $("div.bd-header-article").addClass("noprint"); - $("div.bd-header-announcement").addClass("noprint"); - $("footer.bd-footer-article").addClass("noprint"); + document.querySelector("div.bd-sidebar-primary").classList.add("noprint"); + document.querySelector("div.bd-sidebar-secondary").classList.add("noprint"); + document.querySelector("div.bd-header-article").classList.add("noprint"); + document.querySelector("div.bd-header-announcement").classList.add("noprint"); + document.querySelector("footer.bd-footer-article").classList.add("noprint"); } /** @@ -185,7 +181,6 @@ function setMode() { * Set up callback functions for UI click actions */ window.initThebeSBT = initThebeSBT; -window.printPdf = printPdf; window.toggleFullScreen = toggleFullScreen; /** diff --git a/src/sphinx_book_theme/assets/styles/abstracts/_variables.scss b/src/sphinx_book_theme/assets/styles/abstracts/_variables.scss index ef3694e0b..7d96abb10 100644 --- a/src/sphinx_book_theme/assets/styles/abstracts/_variables.scss +++ b/src/sphinx_book_theme/assets/styles/abstracts/_variables.scss @@ -7,11 +7,6 @@ $breakpoint-lg: 992px; $breakpoint-md: 768px; $breakpoint-sm: 576px; -// Z-index stacking (from Bootstrap) -// ref: https://getbootstrap.com/docs/5.0/layout/z-index/ -$zindex-sticky: 1020; -$zindex-offcanvas: 1100; // We increase this to be over the tooltips - // A few semantic z-indices $zindex-bottom: 1; $zindex-middle: 2; diff --git a/src/sphinx_book_theme/assets/styles/sections/_header-article.scss b/src/sphinx_book_theme/assets/styles/sections/_header-article.scss index 53a0b5be9..bd0fdbf13 100644 --- a/src/sphinx_book_theme/assets/styles/sections/_header-article.scss +++ b/src/sphinx_book_theme/assets/styles/sections/_header-article.scss @@ -137,13 +137,3 @@ div.header-article-main { } } } - -/** - * Tooltips added by bootstrap - * These are added to the bottom of the `` block by JavaScript. - * We should consider removing custom tooltips as this is pretty hacky... - */ -// Ensure that tooltips are *below* the sidebar toggles on mobile -div.tooltip { - z-index: 1049; -} diff --git a/src/sphinx_book_theme/header_buttons/__init__.py b/src/sphinx_book_theme/header_buttons/__init__.py index d272efc15..3fe157ddf 100644 --- a/src/sphinx_book_theme/header_buttons/__init__.py +++ b/src/sphinx_book_theme/header_buttons/__init__.py @@ -113,8 +113,6 @@ def add_header_buttons(app, pagename, templatename, context, doctree): # If we have multiple repo buttons enabled, add a group, otherwise just 1 button if len(repo_buttons) > 1: - for rb in repo_buttons: - rb["tooltip_placement"] = "left" header_buttons.append( { "type": "group", @@ -142,7 +140,6 @@ def add_header_buttons(app, pagename, templatename, context, doctree): "text": ".ipynb", "icon": "fas fa-code", "tooltip": "Download notebook file", - "tooltip_placement": "left", } ) @@ -152,17 +149,15 @@ def add_header_buttons(app, pagename, templatename, context, doctree): "url": f'{pathto("_sources", 1)}/{context["sourcename"]}', "text": suff, "tooltip": "Download source file", - "tooltip_placement": "left", "icon": "fas fa-file", } ) download_buttons.append( { "type": "javascript", - "javascript": "printPdf(this)", + "javascript": "window.print()", "text": ".pdf", "tooltip": "Print to PDF", - "tooltip_placement": "left", "icon": "fas fa-file-pdf", } ) diff --git a/src/sphinx_book_theme/header_buttons/launch.py b/src/sphinx_book_theme/header_buttons/launch.py index c5b220b0d..980d541a6 100644 --- a/src/sphinx_book_theme/header_buttons/launch.py +++ b/src/sphinx_book_theme/header_buttons/launch.py @@ -176,8 +176,6 @@ def add_launch_buttons( context["use_thebe"] = True # Add the buttons to header_buttons - for lb in launch_buttons_list: - lb["tooltip_placement"] = "left" header_buttons.append( { "type": "group", diff --git a/src/sphinx_book_theme/theme/sphinx_book_theme/macros/buttons.html b/src/sphinx_book_theme/theme/sphinx_book_theme/macros/buttons.html index b0bf892aa..7e9287bc9 100644 --- a/src/sphinx_book_theme/theme/sphinx_book_theme/macros/buttons.html +++ b/src/sphinx_book_theme/theme/sphinx_book_theme/macros/buttons.html @@ -1,11 +1,4 @@ {# Utility macros we'll re-use below -#} -{% macro render_tooltip_metadata(tooltip, tooltip_placement) -%} -data-toggle="tooltip" -data-placement="{{ tooltip_placement }}" -title="{{ translate(tooltip) }}" -{%- endmacro %} - - {% macro render_inner_html(icon, text) %} {# used across multiple button types #} {% if icon -%} @@ -21,20 +14,20 @@ {% endmacro %} -{% macro render_link_button(url, tooltip=None, icon=None, text=None, label=None, classes="", tooltip_placement="bottom") -%} +{% macro render_link_button(url, tooltip=None, icon=None, text=None, label=None, classes="") -%} {{ render_inner_html(icon, text) }} {% endmacro %} -{% macro render_js_button(javascript, tooltip=None, icon=None, text=None, label=None, classes="", tooltip_placement="bottom") %} +{% macro render_js_button(javascript, tooltip=None, icon=None, text=None, label=None, classes="") %} diff --git a/src/sphinx_book_theme/theme/sphinx_book_theme/sections/header-article.html b/src/sphinx_book_theme/theme/sphinx_book_theme/sections/header-article.html index 2e158d46a..bc2c8ba4c 100644 --- a/src/sphinx_book_theme/theme/sphinx_book_theme/sections/header-article.html +++ b/src/sphinx_book_theme/theme/sphinx_book_theme/sections/header-article.html @@ -4,7 +4,7 @@
-
@@ -14,7 +14,7 @@ {%- endfor -%} {% if page_toc -%} -