-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-slides
executable file
·92 lines (82 loc) · 3.06 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/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).
// Special escaping symbols to be escaped first
// Special escapes for span/fragment stuff.
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(/<gray>/g, '<span class="gray-code">').
replace(/<\/(frag|mark|gray)>/g, '</span>').
// Replace symbols with html codes to avoid
// rendering them as markdown.
// Except for these, ecaping these breaks everything
//replace(/\&/g, '&').
//replace(/\;/g, ';').
//replace(/\</g, '<').
//replace(/\=/g, '=').
//replace(/\>/g, '>').
//replace(/\#/g, '#').
//replace(/\-/g, '-').
// Ok onto the ones we'll escape
replace(/\!/g, '!').
replace(/\$/g, '$').
replace(/\%/g, '%').
replace(/\(/g, '(').
replace(/\)/g, ')').
replace(/\*/g, '*').
replace(/\+/g, '+').
replace(/\,/g, ',').
replace(/\./g, '.').
replace(/\:/g, ':').
replace(/\?/g, '?').
replace(/\@/g, '@').
replace(/\^/g, '^').
replace(/\_/g, '_').
replace(/\`/g, '`'). //` <- fixes syntax highlight in vim :(
replace(/\{/g, '{').
replace(/\|/g, '|').
replace(/\}/g, '}').
replace(/\~/g, '~').
// toString() is unnecessary but makes it easier to
// just do trailing dots on every line above.
toString();
// 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');