Skip to content

Commit a5695d4

Browse files
committed
Update html build process to use Markdown input
1 parent 038d3aa commit a5695d4

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ html: $(foreach CHAP,$(CHAPTERS),html/$(CHAP).html) html/js/acorn_codemirror.js
88
code/skillsharing.zip code/solutions/20_4_a_public_space_on_the_web.zip html/js/chapter_info.js \
99
$(patsubst img/%.svg,img/generated/%.png,$(SVGS))
1010

11-
html/%.html: %.txt asciidoc_html.conf
12-
PATH=node_modules/codemirror/bin:$(PATH) asciidoc -f asciidoc_html.conf --backend=html5 -o - $< | node bin/addmarks > $@
13-
node bin/build_code.js $<
11+
html/%.html: %.md
12+
node src/render_html.js $< > $@
13+
node src/build_code.js $<
1414

1515
html/js/chapter_info.js: $(foreach CHAP,$(CHAPTERS),$(CHAP).txt) code/solutions/* bin/chapter_info.js
1616
node bin/chapter_info.js > html/js/chapter_info.js

src/build_code.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var fs = require("fs");
2+
3+
var file = process.argv[2];
4+
var input = fs.readFileSync(file, "utf8");
5+
6+
var included = /\{\{includeCode\b(.*)\}\}(?:\s|\{\{.*)*```.*\n([^]*?\n)```/g, m;
7+
var files = Object.create(null);
8+
var defaultFile = "code/chapter/" + file.replace(".md", ".js");
9+
10+
while (m = included.exec(input)) {
11+
var snippet = m[2], directive = JSON.parse(m[1]), file = defaultFile;
12+
snippet = snippet.replace(/(\n|^)\s*\/\/ .*\n/g, "$1");
13+
if (directive.indexOf("strip_log") > -1)
14+
snippet = snippet.replace(/(\n|^)\s*console\.log\(.*\);\n/g, "$1");
15+
if (m = directive.match(/top_lines:\s*(\d+)/))
16+
snippet = snippet.split("\n").slice(0, Number(m[1])).join("\n") + "\n";
17+
if (m = directive.match(/\s>(\S+)/))
18+
file = m[1];
19+
if (file in files)
20+
files[file].push(snippet);
21+
else
22+
files[file] = [snippet];
23+
}
24+
25+
for (var file in files)
26+
fs.writeFileSync(file, files[file].join("\n"), "utf8");

0 commit comments

Comments
 (0)