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