-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgen_doc.pl
executable file
·50 lines (40 loc) · 976 Bytes
/
gen_doc.pl
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
#!/usr/bin/perl
#
# This is my most hacked perl script ever, be warned
#
use warnings;
use strict;
open(IN, "./README.md") or die $!;
open(OUT, ">","./tmp.js") or die $!;
open(TMPL, "./target/index.tmpl.html") or die $!;
open(INDEX, ">", "./target/index.html") or die $!;
print OUT "var marked = require('marked');\n"
."marked.setOptions({gfm: true});\n"
."marked.setOptions({"
." highlight: function (code) {"
." return require('highlight.js').highlightAuto(code).value;"
." }"
."});"
."console.log(marked( [";
foreach(<IN>) {
tr/"/'/;
chomp;
print OUT "\"$_\",\n";
}
print OUT '].join(\'\n\')));'."\n";
close(IN);
close(OUT);
# unlink is delete in perl parlance
my @doc = `node tmp.js` or (unlink("tmp.js") and die $!);
unlink("tmp.js");
foreach(<TMPL>){
if(/{{{README}}}/){
foreach my $d (@doc){
print INDEX $d;
}
} else {
print INDEX $_;
}
}
close(TMPL);
close(INDEX);