-
Notifications
You must be signed in to change notification settings - Fork 29
/
make-html
executable file
·88 lines (72 loc) · 1.88 KB
/
make-html
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
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
load 'make-common'
def usage
puts <<USAGE
Usage:
make-html [markdown]
Options:
-d, --debug : debuging
USAGE
exit
end
# re-generate all if nothing
if ARGV.empty?
$DEBUG = true
Dir["#$here/chap*/doc.markdown"].each do |file|
ARGV.push(file)
end
end
def html_pre_pandoc(string)
replace(string) do
# Inc one category depth
s /^\# /, '## '
s '../img/', 'img/'
end
end
def html_post_pandoc(string, config)
replace(string) do
space = /\s/
# Enable proper cross-reference
pre = config['prechap' ].gsub(space, '\s')
post = config['postchap'].gsub(space, '\s')
s /#{pre}\s*(\d+)(\s*)#{post}/, '<a href="chap\1.html">\0</a>'
end
end
figures do
config = $config['default'].merge($config["ko"])
ARGV.sort.map do |file|
markdown = File.read(file)
print "\tParsing markdown #{file}\n" if $DEBUG
info = {
"title" => "",
"abstract" => "",
}
html = pipe("pandoc -f markdown -t json \
| runhaskell #$here/script/pygments.hs \
| pandoc -s -p --no-wrap -f json -t html \
--template=#$here/html/template-pandoc.html") do |stdin, stdout, stderr|
# extract info
info.each_key do |key|
blob = markdown.scan(/^% #{key}:(.*)/).join
blob.gsub("\n", "")
info[key] = blob
end
# pre-processing for html
markdown = html_pre_pandoc(markdown)
stdin.write(pre_pandoc(markdown, config))
stdin.close
html_post_pandoc(stdout.read, config)
end
unless html
puts "Got error on executing pondoc"
exit 1
end
chap = /chap(\d+)/.match(file)[1]
date = html_mtime(chap)
File.open("#$here/html/chap#{chap}.html", 'w') do |file|
template = $chap_template.result(binding)
file.write($base_template.result(binding))
end
end
end