Skip to content

Commit 0a347e7

Browse files
committed
doc: Run language ref through prep.js
This is so we can strip out support code needed to make the examples work, and as a bonus it does syntax highlighting.
1 parent 57281f5 commit 0a347e7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

doc/prep.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ var out = outfile ? fs.createWriteStream(outfile) : process.stdout;
4040
while ((line = lines[cur++]) != null) {
4141
if (/^~~~/.test(line)) {
4242
var block = "", bline;
43-
var isRust = !/notrust/.test(line);
43+
var notRust =
44+
/notrust/.test(line)
45+
// These are all used by the language ref to indicate things
46+
// that are not Rust source code
47+
|| /ebnf/.test(line)
48+
|| /abnf/.test(line)
49+
|| /keyword/.test(line)
50+
|| /field/.test(line)
51+
|| /precedence/.test(line);
52+
var isRust = !notRust;
4453
while ((bline = lines[cur++]) != null) {
4554
if (/^~~~/.test(bline)) break;
4655
if (!/^\s*##? /.test(bline)) block += bline + "\n";

mk/docs.mk

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@ ifeq ($(CFG_PANDOC),)
1212
$(info cfg: no pandoc found, omitting doc/rust.pdf)
1313
else
1414

15+
ifeq ($(CFG_NODE),)
16+
$(info cfg: no node found, omitting doc/tutorial.html)
17+
else
18+
1519
DOCS += doc/rust.html
1620
doc/rust.html: rust.md doc/version.md doc/keywords.md $(S)doc/rust.css
1721
@$(call E, pandoc: $@)
18-
$(Q)"$(CFG_PANDOC)" \
22+
$(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
23+
"$(CFG_PANDOC)" \
1924
--standalone --toc \
2025
--section-divs \
2126
--number-sections \
2227
--from=markdown --to=html \
2328
--css=rust.css \
24-
--output=$@ \
25-
$<
29+
--output=$@
2630
@$(call E, cp: $(S)doc/rust.css)
2731
-$(Q)cp -a $(S)doc/rust.css doc/rust.css 2> /dev/null
2832

33+
endif
2934

3035
ifeq ($(CFG_PDFLATEX),)
3136
$(info cfg: no pdflatex found, omitting doc/rust.pdf)

0 commit comments

Comments
 (0)