diff --git a/_static/activate_tab.js b/_static/activate_tab.js new file mode 100644 index 0000000000..8b5fcbabd9 --- /dev/null +++ b/_static/activate_tab.js @@ -0,0 +1,42 @@ +// Based on https://stackoverflow.com/a/38241481/724176 +function getOS() { + const userAgent = window.navigator.userAgent, + platform = + window.navigator?.userAgentData?.platform || window.navigator.platform, + macosPlatforms = ["macOS", "Macintosh", "MacIntel", "MacPPC", "Mac68K"], + windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"], + iosPlatforms = ["iPhone", "iPad", "iPod"]; + + if (macosPlatforms.includes(platform)) { + return "macOS"; + } else if (iosPlatforms.includes(platform)) { + return "iOS"; + } else if (windowsPlatforms.includes(platform)) { + return "Windows"; + } else if (/Android/.test(userAgent)) { + return "Android"; + } else if (/Linux/.test(platform)) { + return "Unix"; + } + + return "unknown"; +} + +function activateTab(tabName) { + // Find all label elements containing the specified tab name + const labels = document.querySelectorAll(".tab-label"); + + labels.forEach((label) => { + if (label.textContent.includes(tabName)) { + // Find the associated input element using the 'for' attribute + const tabInputId = label.getAttribute("for"); + const tabInput = document.getElementById(tabInputId); + + // Check if the input element exists before attempting to set the "checked" attribute + if (tabInput) { + // Activate the tab by setting its "checked" attribute to true + tabInput.checked = true; + } + } + }); +} diff --git a/conf.py b/conf.py index c0997f017e..31ce4f5fd6 100644 --- a/conf.py +++ b/conf.py @@ -45,6 +45,9 @@ html_css_files = [ 'devguide_overrides.css', ] +html_js_files = [ + "activate_tab.js", +] html_logo = "_static/python-logo.svg" html_favicon = "_static/favicon.png" diff --git a/index.rst b/index.rst index 987f6b4bc3..0621180e75 100644 --- a/index.rst +++ b/index.rst @@ -2,6 +2,14 @@ Python Developer's Guide ======================== +.. raw:: html + + + .. highlight:: bash This guide is a comprehensive resource for :ref:`contributing ` diff --git a/testing/run-write-tests.rst b/testing/run-write-tests.rst index 58e56297d0..6fa9b04a58 100644 --- a/testing/run-write-tests.rst +++ b/testing/run-write-tests.rst @@ -5,6 +5,14 @@ Running and writing tests ========================= +.. raw:: html + + + .. note:: This document assumes you are working from an