forked from nathangrigg/vimhelppdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathh2h.py
More file actions
executable file
·71 lines (57 loc) · 1.63 KB
/
h2h.py
File metadata and controls
executable file
·71 lines (57 loc) · 1.63 KB
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
#!/usr/bin/python
import sys
import os.path
import codecs
# import cProfile
from vimh2h import VimH2H
SECTION_BEGIN = r"""\addcontentsline{toc}{%s}{%s}
\markright{%s}
\begin{Verbatim}[commandchars=\\\{\},formatcom=\fixurl]
"""
CHAPTER_BEGIN = r"""\addcontentsline{toc}{%s}{%s}
"""
SECTION_END = """
\\end{Verbatim}
\\newpage\\phantomsection{}
"""
DOC_END = r"""
\addcontentsline{toc}{%s}{About this pdf}
\markright{about this pdf}
"""
def slurp(filename):
f = open(filename)
c = f.read()
f.close()
return c
def main():
print "Processing tags..."
h2h = VimH2H(slurp('doc/tags'))
h2h.add_tags(slurp('doc/vim_faq.txt'))
contents = slurp('contents.txt').split('\n')
fout = codecs.open('body.tex', 'w', 'utf-8')
level = "chapter"
for row in contents:
split_row = row.strip().split(None, 1)
if len(split_row) != 2:
continue
filename, title = split_row
if filename == "#":
fout.write(CHAPTER_BEGIN % ("chapter", title))
level = "section"
continue
if filename == "##":
fout.write(CHAPTER_BEGIN % ("section", title))
level = "subsection"
continue
fout.write(SECTION_BEGIN % (level, title, filename.replace('_', r'\_')))
print "Processing " + filename + "..."
text = slurp(os.path.join('doc', filename))
try:
text = text.decode('UTF-8')
except UnicodeError:
text = text.decode('ISO-8859-1')
fout.write(h2h.to_tex(filename, text))
fout.write(SECTION_END)
fout.write(DOC_END % level)
main()
# cProfile.run('main()')