| 1 |
# Syntax highlighting |
| 2 |
|
| 3 |
mdBook uses [Highlight.js](https://highlightjs.org) with a custom theme |
| 4 |
for syntax highlighting. |
| 5 |
|
| 6 |
Automatic language detection has been turned off, so you will probably want to |
| 7 |
specify the programming language you use like this: |
| 8 |
|
| 9 |
~~~markdown |
| 10 |
```rust |
| 11 |
fn main() { |
| 12 |
// Some code |
| 13 |
} |
| 14 |
``` |
| 15 |
~~~ |
| 16 |
|
| 17 |
## Supported languages |
| 18 |
|
| 19 |
These languages are supported by default, but you can add more by supplying |
| 20 |
your own `highlight.js` file: |
| 21 |
|
| 22 |
- apache |
| 23 |
- armasm |
| 24 |
- bash |
| 25 |
- c |
| 26 |
- coffeescript |
| 27 |
- cpp |
| 28 |
- csharp |
| 29 |
- css |
| 30 |
- d |
| 31 |
- diff |
| 32 |
- go |
| 33 |
- handlebars |
| 34 |
- haskell |
| 35 |
- http |
| 36 |
- ini |
| 37 |
- java |
| 38 |
- javascript |
| 39 |
- json |
| 40 |
- julia |
| 41 |
- kotlin |
| 42 |
- less |
| 43 |
- lua |
| 44 |
- makefile |
| 45 |
- markdown |
| 46 |
- nginx |
| 47 |
- nim |
| 48 |
- nix |
| 49 |
- objectivec |
| 50 |
- perl |
| 51 |
- php |
| 52 |
- plaintext |
| 53 |
- properties |
| 54 |
- python |
| 55 |
- r |
| 56 |
- ruby |
| 57 |
- rust |
| 58 |
- scala |
| 59 |
- scss |
| 60 |
- shell |
| 61 |
- sql |
| 62 |
- swift |
| 63 |
- typescript |
| 64 |
- x86asm |
| 65 |
- xml |
| 66 |
- yaml |
| 67 |
|
| 68 |
## Custom theme |
| 69 |
Like the rest of the theme, the files used for syntax highlighting can be |
| 70 |
overridden with your own. |
| 71 |
|
| 72 |
- ***highlight.js*** normally you shouldn't have to overwrite this file, unless |
| 73 |
you want to use a more recent version. |
| 74 |
- ***highlight.css*** theme used by highlight.js for syntax highlighting. |
| 75 |
|
| 76 |
If you want to use another theme for `highlight.js` download it from their |
| 77 |
website, or make it yourself, rename it to `highlight.css` and put it in |
| 78 |
the `theme` folder of your book. |
| 79 |
|
| 80 |
Now your theme will be used instead of the default theme. |
| 81 |
|
| 82 |
## Improve default theme |
| 83 |
|
| 84 |
If you think the default theme doesn't look quite right for a specific language, |
| 85 |
or could be improved, feel free to [submit a new |
| 86 |
issue](https://github.com/rust-lang/mdBook/issues) explaining what you |
| 87 |
have in mind and I will take a look at it. |
| 88 |
|
| 89 |
You could also create a pull-request with the proposed improvements. |
| 90 |
|
| 91 |
Overall the theme should be light and sober, without too many flashy colors. |