forked from jantman/misc-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiki-to-deckjs.py
executable file
·94 lines (83 loc) · 2.36 KB
/
wiki-to-deckjs.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python2
"""
simple, awful script to change markdown-like (very restricted markup set) markup to deck.js-ready html
##################
Copyright 2014 Jason Antman <jason@jasonantman.com> <http://www.jasonantman.com>
Free for any use provided that patches are submitted back to me.
The latest version of this script can be found at:
https://github.com/jantman/misc-scripts/blob/master/wiki-to-deckjs.py
CHANGELOG:
- initial version
"""
import sys
import re
ol_re = re.compile(r"^\d+\.\s(.*)")
in_slide = False
in_ul = False
in_2ul = False
in_ol = False
for line in sys.stdin:
if line.strip() == "":
if in_slide:
if in_2ul:
print "\t\t</ul>"
in_2ul = False
if in_ul:
print "\t</ul>"
in_ul = False
if in_ol:
print "\t</ol>"
in_ol = False
print '</section>'
in_slide = False
continue
else:
if not in_slide:
in_slide = True
print '<section class="slide">'
if in_2ul and not line.startswith("** "):
print "\t\t</ul>"
in_2ul = False
if in_ul and not line.startswith("* ") and not line.startswith("** ") and not in_2ul:
print "\t</ul>"
in_ul = False
if in_ol and not ol_re.match(line):
print "\t</ol>"
in_ul = False
if not in_slide:
continue
if line.startswith("# "):
line = line[2:].strip()
print "\t<h1>%s</h1>" % line
elif line.startswith("## "):
line = line[2:].strip()
print "\t<h2>%s</h2>" % line
elif line.startswith("* "):
if not in_ul:
print "\t<ul>"
in_ul = True
line = line[2:].strip()
print "\t\t<li>%s</li>" % line
elif line.startswith("** "):
if not in_2ul:
print "\t\t<ul>"
in_2ul = True
line = line[3:].strip()
print "\t\t\t<li>%s</li>" % line
elif ol_re.match(line):
m = ol_re.match(line)
if not in_ol:
print "\t<ol>"
in_ol = True
print "\t\t<li>%s</li>" % m.group(1)
else:
#sys.stderr.write("UNKNOWN LINE: %s\n" % line)
print "\t<p>%s</p>" % line.strip()
if in_2ul:
print "\t\t</ul>"
in_2ul = False
if in_ul:
print "\t</ul>"
in_ul = False
print '</section>'
# done