-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.py
66 lines (59 loc) · 2.56 KB
/
doc.py
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
import codecs
import os
import sys
import markdown
import typogrify
HEADER = """<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>%s</title>
<style type="text/css" media="screen,projection">
*{font-size:1em;font-style:inherit;font-weight:inherit;margin:0;padding:0}
body{background:#fff;color:#222;font:100%%/1.5 "Helvetica Neue",Arial,Helvetica,sans-serif;margin:0;padding:3em}
a{border-bottom:1px solid;color:#00c;font-weight:inherit;padding-bottom:1px;text-decoration:none}
strong{font-weight:bold}
em{font-style:italic}
code{background:#ddd;font:100%%/0 Monaco,monospace}
h1{font-size:2em;font-weight:bold;line-height:1.5em;padding:0 0 0.75em}
h2{font-size:1.5em;font-weight:bold;line-height:2em}
h3{font-size:1.2em;font-weight:bold;line-height:1.25em;padding:0.625em 0}
p,ul,ol,.address{padding:0 0 1.5em}
ul,ol{padding-left:1.5em}
pre{background:#ddd;border:1px solid #bbb;font:100%%/1.5 Monaco,monospace;margin:-2px -1px 1.5em;padding:1.5em}
.address span{display:block}
</style>
<style type="text/css" media="print">
*{font-size:1em;font-style:inherit;font-weight:inherit;margin:0;padding:0}
body{background:#fff;color:#222;font:100%%/1.5 "Helvetica Neue",Arial,Helvetica,sans-serif;padding:3em}
a{color:inherit;font-weight:inherit;text-decoration:none}
a:not([href^=mailto]):after{color:#666;content:" (" attr(href) ")";font-size:0.9em}
.nolink a:after{content:""}
strong{font-weight:bold}
em{font-style:italic}
code{background:#ddd;font:100%%/0 Monaco,monospace}
h1{font-size:2em;font-weight:bold;line-height:1.5em;padding:0 0 0.75em;page-break-after:avoid}
h2{font-size:1.5em;font-weight:bold;line-height:2em;page-break-after:avoid}
h3{font-size:1.2em;font-weight:bold;line-height:1.25em;padding:0.625em 0;page-break-after:avoid}
p,ul,ol,.address{padding:0 0 1.5em}
ul,ol{padding-left:1.5em}
pre{background:#ddd;border:1px solid #bbb;font:100%%/1.5 Monaco,monospace;margin:-2px -1px 1.5em;padding:1.5em}
.address span{display:block}
</style>
</head>
<body>"""
FOOTER = """</body></html>"""
if __name__ == '__main__':
if (len(sys.argv) > 1):
filename = sys.argv[1]
in_file = codecs.open(filename, encoding='utf-8')
md = in_file.read()
in_file.close()
title = os.path.basename(filename)
content = typogrify.typogrify(
markdown.markdown(md, ['abbr', 'headerid']))
out_file = codecs.open(filename + '.html', encoding='utf-8', mode='w+')
out_file.write((HEADER % title) + content + FOOTER)
out_file.close()
else:
print u'Filename not supplied.'