-
Notifications
You must be signed in to change notification settings - Fork 345
/
magicmarkdown.py
executable file
·49 lines (40 loc) · 1.52 KB
/
magicmarkdown.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
"""
magicmarkdown.py
utility script for changing markdown from magic methods guide into HTML
"""
import markdown
HEADER = """<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>A Guide to Python's Magic Methods « rafekettler.com</title>
<meta name="description" content="A guide to all the Magic Methods in Python" />
<meta name="keywords" content="python, programming, magic methods, object-oriented, oop" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
"""
FOOTER = """<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18615621-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
"""
table = open('table.markdown').read()
body = open('magicmethods.markdown').read()
appendix = open('appendix.markdown').read()
table_text = markdown.markdown(table)
body_text = markdown.markdown(body,
['def_list', 'codehilite'])
appendix_text = markdown.markdown(appendix, ['tables'])
with open('magicmethods.html', 'w') as out:
out.write(HEADER)
out.write(table_text)
out.write(body_text)
out.write(appendix_text)
out.write(FOOTER)