add preformatted text support

This commit is contained in:
randomuser 2021-06-30 15:03:21 -05:00
parent 1e85a2ea84
commit d75303faa1
1 changed files with 16 additions and 2 deletions

18
uml.py
View File

@ -126,12 +126,15 @@ def renderer(chain):
cbuf = " "
cbuf += i
print(cbuf)
elif i.element == "x":
print(i.data)
if rendered: print()
chain = []
flags = {
"TABLE_PREV": False,
"PARA_PREV": False,
"IN_PREFORMATTED": False,
}
def main():
for i in finput():
@ -141,7 +144,7 @@ def main():
if len(i) == 0: continue
# lines with text
if i[0].isalpha():
if i[0].isalpha() and not flags["IN_PREFORMATTED"]:
if not flags["PARA_PREV"]:
flags["PARA_PREV"] = True
chain.append(Element("p", i))
@ -152,8 +155,17 @@ def main():
chain[-1].data += i
continue
if i[0:3] == '```':
if not flags["IN_PREFORMATTED"]:
flags["IN_PREFORMATTED"] = True
params = i[3:]
chain.append(Element("x", "", params))
else:
flags["IN_PREFORMATTED"] = False
continue
# we have a processing command
if not i[0].isalpha():
if not i[0].isalpha() and not flags["IN_PREFORMATTED"]:
command = ""
params = ""
counter = 0
@ -185,6 +197,8 @@ def main():
flags["TABLE_PREV"] = False
flags["PARA_PREV"] = False
continue
elif flags["IN_PREFORMATTED"]:
chain[-1].data += i + "\n"
renderer(chain)
if __name__ == "__main__": main()