語法標明
mdBook 使用 Highlight.js 搭配自訂主題來進行語法標明。
已關閉自動語言偵測,因此您可能會想像這樣指定您使用的程式語言:
```rust
fn main() {
// Some code
}
```
支援的語言
這些語言預設皆有支援,但您也可以透過提供自訂的 highlight.js 檔案來增加更多語言:
- apache
- armasm
- bash
- c
- coffeescript
- cpp
- csharp
- css
- d
- diff
- go
- handlebars
- haskell
- http
- ini
- java
- javascript
- json
- julia
- kotlin
- less
- lua
- makefile
- markdown
- nginx
- nim
- nix
- objectivec
- perl
- php
- plaintext
- properties
- python
- r
- ruby
- rust
- scala
- scss
- shell
- sql
- swift
- typescript
- x86asm
- xml
- yaml
自訂主題
與主題的其他部分相同,用於語法標明的檔案也可以替換為您自己的檔案。
- highlight.js normally you shouldn’t have to overwrite this file, unless you want to use a more recent version.
- highlight.css 是 highlight.js 用於語法標明的主題。
If you want to use another theme for highlight.js download it from their website, or make it yourself, rename it to highlight.css and put it in the theme folder of your book.
Now your theme will be used instead of the default theme.
改善預設主題
If you think the default theme doesn’t look quite right for a specific language, or could be improved, feel free to submit a new issue explaining what you have in mind and I will take a look at it.
You could also create a pull-request with the proposed improvements.
Overall the theme should be light and sober, without too many flashy colors.