forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-html.py
More file actions
executable file
·57 lines (45 loc) · 1.49 KB
/
Copy pathpre-html.py
File metadata and controls
executable file
·57 lines (45 loc) · 1.49 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
#!/usr/bin/python
while True:
try:
line = raw_input()
except:
break
# General patching
# 
# 
if line.find('!') == 0 :
oparen = line.find('(')
cparen = line.find(')')
obrack = line.find('[')
cbrack = line.find(']')
atsign = line.find('@')
if atsign < 0 : atsign=oparen
if cparen < atsign or cparen < 1 or oparen < 1 or atsign < 1 :
print line
continue
linktext = ''
if obrack > 0 and cbrack > 0 and cbrack > obrack :
linktext = line[obrack+1:cbrack]
attribs = dict()
if atsign > oparen :
attribsstr = line[oparen+1:atsign]
pieces = attribsstr.split(',')
for piece in pieces:
kvp = piece.split('=');
if len(kvp) != 2 : continue
attribs[kvp[0]] = kvp[1]
fname = line[atsign+1:cparen]
try:
fh = open(fname+'.svg')
fname = fname+'.svg'
except:
fname = fname+'.png'
if attribs.get('height') :
print '<figure>'
print '<img src="'+fname+'" alt="'+linktext+'" style="height: '+attribs.get('height')+';"/>'
print '<figcaption>'+linktext+'</figcaption>'
print '</figure>'
else :
print line[:oparen+1]+fname+')'
continue
print line