How to display line numbers in code blocks in mdbook?

Hi, i have been trying to display the line numbers on the left side in Rust code blocks in mdbook, i want to display the line numbers without making the code block editable. Any ideas on how to do that ?

fn main() {
    println!("Hello, world!");

mdBook only supports line numbers on editable code blocks. According to the mdBook documentation:

  • line-numbers Display line numbers on editable sections of code. Requires both editable and copy-js to be true. Defaults to false.

If you need line numbers on non-editable code blocks, you will need to fork the mdBook code and make the changes yourself.

1 Like

alternatively, inject custom js code using the additional-js config option:

for instance, the first result googling "highlightjs line number plugin" is:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.