Skip to content

Commit f252933

Browse files
committed
support for multi-language code block tab syncing
1 parent 27223ce commit f252933

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

docs/tabsync.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
document.addEventListener("DOMContentLoaded", function () {
2+
const tabSync = () => {
3+
const tabs = document.querySelectorAll(".tabbed-set > input, .tabbed-alternate input");
4+
5+
for (const tab of tabs) {
6+
tab.addEventListener("click", () => {
7+
const currentLabel = document.querySelector(`label[for="${tab.id}"]`);
8+
if (!currentLabel) return;
9+
10+
const pos = currentLabel.getBoundingClientRect().top;
11+
const labelText = currentLabel.textContent.trim();
12+
13+
const allLabels = document.querySelectorAll(
14+
".tabbed-set > label, .tabbed-alternate > .tabbed-labels > label"
15+
);
16+
17+
for (const label of allLabels) {
18+
if (label.textContent.trim() === labelText) {
19+
const inputId = label.getAttribute("for");
20+
const input = document.getElementById(inputId);
21+
if (input && input !== tab) {
22+
input.click();
23+
}
24+
}
25+
}
26+
27+
const delta = currentLabel.getBoundingClientRect().top - pos;
28+
window.scrollBy(0, delta);
29+
});
30+
}
31+
};
32+
33+
tabSync();
34+
});

mkdocs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ site_description: 'Documentation for the Binary Ninja reverse engineering platfo
77
site_author: 'Vector 35 Inc'
88
use_directory_urls: false
99
extra_css: ['docs.css', 'github.min.css', 'juxtapose.min.css']
10-
extra_javascript: ['highlight.min.js', 'cpp.min.js', 'python.min.js', 'juxtapose.min.js']
10+
extra_javascript: ['highlight.min.js', 'cpp.min.js', 'python.min.js', 'juxtapose.min.js', 'tabsync.js']
1111
theme:
1212
name: material
1313
custom_dir: overrides
@@ -76,7 +76,8 @@ markdown_extensions:
7676
- codehilite
7777
- admonition
7878
- pymdownx.details
79-
- pymdownx.superfences
79+
- pymdownx.superfences:
80+
preserve_tabs: true
8081
- pymdownx.tabbed:
8182
alternate_style: true
8283
- toc:

0 commit comments

Comments
 (0)