-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-slides
executable file
·53 lines (46 loc) · 1.81 KB
/
gen-slides
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
const fs = require('fs');
const _ = require('./js/underscore-min.js');
var inCodeBlock = false;
var out =
'<!--\n' +
'**** THIS IS A GENERATED FILE, DO NOT EDIT! ****\n' +
'**** CHANGES SHOULD BE MADE IN slides.md INSTEAD! ****\n' +
'-->\n';
// Escape HTML in code blocks except for spans to allow for fragment/mark.
// The trailing dots are needed due to js' clunky indent rules.
const escapeCodeBlock = s =>
_.escape(s).
replace(/<frag>/g, '<span class="fragment">').
replace(/<frag (\d+)>/g, '<span class="fragment" data-fragment-index="$1">').
replace(/<mark>/g, '<span class="fragment highlight-red">').
replace(/<mark (\d+)>/g, '<span class="fragment highlight-red" data-fragment-index="$1">').
replace(/<mark (\w+)>/g, '<span class="fragment highlight-$1">').
replace(/<mark (\w+) (\d+)>/g, '<span class="fragment highlight-$1" data-fragment-index="$2">').
replace(/<\/(frag|mark)>/g, '</span>');
// Expand non-code block <frag> elements
const expandMagicTags = s =>
s.replace(/<frag>/g, '<span class="fragment">').
replace(/<frag (\d+)>/g, '<span class="fragment" data-fragment-index="$1">').
replace(/<\/frag>/g, '</span>')
;
fs.readFileSync('./slides.md').toString().split('\n').forEach(line => {
var matcher = /^```(.*)$/.exec(line);
if (matcher === null) {
if (inCodeBlock) {
out += escapeCodeBlock(line) + '\n';
} else {
out += expandMagicTags(line) + '\n';
}
return;
}
if (inCodeBlock) {
inCodeBlock = false;
out += '</code></pre>\n'
return;
}
inCodeBlock = true;
out += '<pre><code data-noescape data-trim class=' + matcher[1] + '>\n';
});
fs.writeFile('slides.gen.md', out, err => { if (err) console.log(err); });
console.log('Generated slides.gen.md');