#mdbook-preprocessor #tabs #markdown

bin+lib mdbook-langtabs

An mdbook preprocessor that adds language tabs for code blocks

2 releases

Uses new Rust 2024

new 0.1.1 Mar 31, 2025
0.1.0 Mar 29, 2025

#639 in Text processing

Download history 98/week @ 2025-03-24

98 downloads per month

MIT license

375KB
582 lines

mdbook-langtabs

Crates.io License: MIT

An mdBook preprocessor that creates language tabs for code examples.

Language tabs example demo

Features

  • Switch between language examples without scrolling
  • Automatic language icons via Devicon
  • Remembers selected language preference

Installation

cargo install mdbook-langtabs

Or install the current development version:

cargo install --git https://github.com/nx10/mdbook-langtabs

Setup

Either use the automatic installer:

mdbook-langtabs install /path/to/your/book

Or manually:

  1. Add to your book.toml:
[preprocessor.langtabs]
command = "mdbook-langtabs"

[output.html]
additional-css = ["langtabs.css"]
additional-js = ["langtabs.js"]
  1. Copy langtabs.css and langtabs.js to your book's root directory.

Usage

Wrap your code blocks with the special comments:

<!-- langtabs-start -->
```rust
fn main() {
    println!("Hello from Rust!");
}
```

```python
def main():
    print("Hello from Python!")
```

```javascript
function main() {
    console.log("Hello from JavaScript!");
}
```
<!-- langtabs-end -->

This creates tabbed code examples that readers can switch between, as shown in the demo above.

License

MIT

Dependencies

~14–25MB
~395K SLoC