Introduction

  • 🎨 Optimized for every theme.
  • 🔥 Zero-Setup installation: Download the standalone files from the repository's releases section or download them via command-line.
  • 🔧 Highly configurable.

Installation

In the directory of your book, install whichlang with the following command.

wget https://github.com/phoenixr-codes/mdbook-whichlang/releases/latest/download/whichlang.js &&
wget https://github.com/phoenixr-codes/mdbook-whichlang/releases/latest/download/whichlang.css

Don't forget to add these files in your book.toml:

# ...

[output.html]
additional-css = ["path/to/whichlang.css"]
additional-js = ["path/to/whichlang.js"]

Uninstallation

Simply remove the whichlang.js and whichlang.css files and remove the references to them in the book.toml configuration file.

Usage

whichlang works out of the box. It detects the language defined on each code block and customizes them appropiately. You can furthermore configure them individually:

  • override the name of the language
  • override the icon of the language
  • set a file path shown in the code block

Cheat Sheet

Disable banner completely

```python,banner=no,icon=rust
def greet():
    print("Hello World")
```

becomes

def greet():
    print("Hello World")

Override/set the icon

```python
def greet():
    print("Hello World")
```

becomes

def greet():
    print("Hello World")
```python,icon=%rust
def greet():
    print("Hello World")
```

becomes

def greet():
    print("Hello World")
```python,icon=
def greet():
    print("Hello World")
```

becomes

def greet():
    print("Hello World")

Set the file path

```python,fp=path/to/file.py
def greet():
    print("Hello World")
```

becomes

def greet():
    print("Hello World")

Using Icons

whichlang uses Simple Icons by default.

Examples

#include <stdio.h>

int main(void) {
	printf("Hello World\n");
}
#include <iostream>

int main()
{
   std::cout << "Hello World" << std::endl;
}
console.log("Hello World");
console.log("Hello World");
Console.log("Hello World")
h1 {
  color: blue;
}
set syntax=ruby
print("Hello World")
print("Hello World")
echo "Hello World"
const std = @import("std");

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("Hello, {s}!\n", .{"world"});
}
package main

import "core:fmt"

main :: proc() {
	fmt.println("Hellope!")
}
(module
    (import "wasi_unstable" "fd_write"
        (func $fd_write (param i32 i32 i32 i32) (result i32))
    )

    (memory 1)
    (export "memory" (memory 0))

    (data (i32.const 0) "\08\00\00\00\0c\00\00\00Hello World\n")

    (func $main (export "_start")
        i32.const 1
        i32.const 0
        i32.const 1
        i32.const 20
        call $fd_write
        drop
    )
)

Kitchen Sink

All combined

import this

Code Blocks in Block Quotes

Hello World.

This is a block quote.

#![allow(unused)]
fn main() {
println!("Hello World");
}

Automatic language detection

[[player]]
name = "john"
score = 3

Enforce no icon

puts "hey"
puts "ho"

External icon

Make sure you have an internet connection.

numpy==1.26.2

Hiding lines

<!DOCTYPE html>
<html>
  <body>
    <h1>Hello World</h1>
    <p>Click on the eye icon on the right side of the code block</p>
    
  </body>
  
</html>

Multiple classes

puts "hi"