Skip to content

Commit 69baf14

Browse files
committed
Highlight Lisp code in guide doc correctly
[skip ci]
1 parent cd00cf2 commit 69baf14

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

guide/book.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ src = "src"
77
[output.html]
88
google-analytics = "UA-138609797-1"
99
additional-css = ["custom.css"]
10-
preferred-dark-theme = "coal"
10+
additional-js = ["hljs-load-langs.js"]
11+
preferred-dark-theme = "coal"

guide/hljs-load-langs.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(function loadLangs() {
2+
// mdbook is not very extensible yet. This is a workaround.
3+
// In the long term, we should probably switch to org-mode.
4+
// See https://github.com/rust-lang/mdBook/issues/657#issuecomment-377935449.
5+
6+
function highlight(lang) {
7+
Array
8+
.from(document.querySelectorAll("code.hljs.language-" + lang))
9+
.forEach(function (block) { hljs.highlightBlock(block); })
10+
}
11+
12+
function load(lang) {
13+
var src = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.9/languages/" + lang + ".min.js";
14+
var s = document.createElement('script');
15+
s.setAttribute('src', src);
16+
s.setAttribute('type', 'text/javascript');
17+
s.setAttribute('charset', 'utf-8');
18+
s.onload = function() {
19+
highlight(lang);
20+
};
21+
document.body.appendChild(s);
22+
}
23+
24+
load('lisp');
25+
})();

guide/src/custom-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn init(env: &Env) -> Result<()> {
4242
}
4343
```
4444

45-
```emacs-lisp
45+
```lisp
4646
(let ((m (rs-hash-map/make)))
4747
(rs-hash-map/get m "a") ; -> nil
4848

guide/src/hello.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ln -s libgreeting.dylib greeting.so
5555
```
5656

5757
Add `target/debug` to your Emacs's `load-path`, then load the module:
58-
```emacs-lisp
58+
```lisp
5959
(add-to-list 'load-path "/path/to/target/debug")
6060
(require 'greeting)
6161
(greeting-say-hello "Emacs")

guide/src/reloading.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Live code reloading is very useful during development. However, Emacs does not s
44

55
To use it, load it in Emacs:
66

7-
```emacs-lisp
7+
```lisp
88
(require 'rs-module)
99
```
1010

1111
Then use it to load other modules instead of `require` or `module-load`:
1212

13-
```emacs-lisp
13+
```lisp
1414
;; Will unload the old version of the module first.
1515
(rs-module/load "full/path/to/module.so")
1616
```

0 commit comments

Comments
 (0)