From f252933553de86be26c25710ca314bc1f15e93b6 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 31 Jul 2025 18:03:27 -0400 Subject: support for multi-language code block tab syncing --- docs/tabsync.js | 34 ++++++++++++++++++++++++++++++++++ mkdocs.yml | 5 +++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 docs/tabsync.js diff --git a/docs/tabsync.js b/docs/tabsync.js new file mode 100644 index 00000000..86e54b1c --- /dev/null +++ b/docs/tabsync.js @@ -0,0 +1,34 @@ +document.addEventListener("DOMContentLoaded", function () { + const tabSync = () => { + const tabs = document.querySelectorAll(".tabbed-set > input, .tabbed-alternate input"); + + for (const tab of tabs) { + tab.addEventListener("click", () => { + const currentLabel = document.querySelector(`label[for="${tab.id}"]`); + if (!currentLabel) return; + + const pos = currentLabel.getBoundingClientRect().top; + const labelText = currentLabel.textContent.trim(); + + const allLabels = document.querySelectorAll( + ".tabbed-set > label, .tabbed-alternate > .tabbed-labels > label" + ); + + for (const label of allLabels) { + if (label.textContent.trim() === labelText) { + const inputId = label.getAttribute("for"); + const input = document.getElementById(inputId); + if (input && input !== tab) { + input.click(); + } + } + } + + const delta = currentLabel.getBoundingClientRect().top - pos; + window.scrollBy(0, delta); + }); + } + }; + + tabSync(); +}); \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index c70be12b..0f9dd11c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -7,7 +7,7 @@ site_description: 'Documentation for the Binary Ninja reverse engineering platfo site_author: 'Vector 35 Inc' use_directory_urls: false extra_css: ['docs.css', 'github.min.css', 'juxtapose.min.css'] -extra_javascript: ['highlight.min.js', 'cpp.min.js', 'python.min.js', 'juxtapose.min.js'] +extra_javascript: ['highlight.min.js', 'cpp.min.js', 'python.min.js', 'juxtapose.min.js', 'tabsync.js'] theme: name: material custom_dir: overrides @@ -76,7 +76,8 @@ markdown_extensions: - codehilite - admonition - pymdownx.details - - pymdownx.superfences + - pymdownx.superfences: + preserve_tabs: true - pymdownx.tabbed: alternate_style: true - toc: -- cgit v1.3.1