-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprop.py
101 lines (95 loc) · 2.6 KB
/
prop.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
95
96
97
98
99
100
101
import fileinput
import sys
import os
import shutil
#Control del preprocesador
stage = 0
properties = {}
preline=0
#banderas
ifformat=0
#macros especiales
scene_header=""
scene_footer=""
action_header=""
action_footer=""
# linea de comando
comando="ficdown"
infile=sys.argv[1].replace('.md','')
outfile=infile
archivo = open(sys.argv[1]+'.prop','w')
for line in fileinput.input(sys.argv[1]):
if line.startswith('---') or line.startswith('***'):
stage += 1
elif stage == 1 and line.startswith('@'):
[macro, config] = line.split(': ')
config = config.splitlines()[0]
#configuracion de ficdown
if (macro=="@format"):
comando+=" --format "+config
ifformat=1
if(config=="epub"):
outfile=infile+".epub"
elif (macro=="@template"):
comando+=" --template \""+config+"\""
elif (macro=="@images"):
comando+=" --images \""+config+"\""
elif (macro=="@author"):
comando+=" --author \""+config+"\""
elif (macro=="@bookid"):
comando+=" --bookid \""+config+"\""
elif (macro=="@language"):
comando+=" --language \""+config+"\""
elif (macro=="@debug" and config=="1"):
comando+=" --debug"
elif (macro=="@scene_header"):
scene_header="\n"+config+"\n"
elif (macro=="@scene_footer"):
scene_footer=config+"\n\n"
elif (macro=="@action_header"):
action_header="\n"+config+"\n"
elif (macro=="@action_footer"):
action_footer=config+"\n\n"
elif stage == 1:
[prop, val] = line.split(': ')
properties[prop] = val.splitlines()[0]
elif stage == 2:
for prop in properties:
# ocurre si se inicia el documento con una scena o una accion
line = line.replace(''.join(['__', prop, '__']), properties[prop])
if(line.startswith('## ') and preline==0):
preline=1
line=line+scene_header
elif(line.startswith('### ') and preline==0):
preline=2
line=line+action_header
elif(line.startswith('## ') and preline==1):
preline=1
line=scene_footer+line+scene_header
elif(line.startswith('### ') and preline==2):
preline=2
line=action_footer+line+action_header
elif(line.startswith('## ') and preline==2):
preline=1
line=action_footer+line+scene_header
elif(line.startswith('### ') and preline==1):
preline=2
line=scene_footer+line+action_header
archivo.write(line)
if(preline==1):
line="\n"+scene_footer
elif(preline==2):
line="\n"+action_footer
else:
line=""
archivo.write(line)
archivo.close()
if os.path.isdir(infile):
shutil.rmtree(infile)
infile+=".md.prop"
if(ifformat==1):
comando+=" --in \""+infile+"\" --out \""+outfile+"\""
else:
comando+=" --format html --in \""+infile+"\" --out \""+outfile+"\""
print(comando)
os.system(comando+"&& rm "+infile)