Better parseRawHTML function

This commit is contained in:
Govindas 2022-01-24 15:20:08 +02:00
parent 16fb70aaeb
commit 1319e9967a
2 changed files with 15 additions and 12 deletions

View File

@ -1,6 +1,9 @@
# Welcome!
This is the homepage of our website.
>
<b>Hello</b>
Another line
<a href=/test>**Another line 2**</a>
<b>HTML Hello</b>
Another markdown line
<a href=/test>**Another markdown line 2**</a>
>
<p><i>**HTML Italics test 1**
<p><i>HTML Italics test 2

View File

@ -22,12 +22,12 @@ except FileExistsError:
def generateNavigationBar(lines):
global navbar
navbar = E
for line in lines:
for id, line in enumerate(lines):
title, link = line.strip().split(";", 1)
navbar = navbar.li(HTML("<a href='" + link + "'>" + title + "</a>"))
def parseRawHTML(doc, line, htmlstring, rawhtml):
def parseRawHTML(doc, line, htmlstring, rawhtml, id, maxlines):
#raw html start
if line.strip() == ">":
rawhtml = True
@ -37,9 +37,13 @@ def parseRawHTML(doc, line, htmlstring, rawhtml):
elif rawhtml:
if line.startswith(" "):
htmlstring = htmlstring + line.strip()
#if indented html was the last line, this is needed for it to not be ignored
if maxlines - id == 1:
doc.div(HTML(htmlstring))
else:
rawhtml = False
doc.div(HTML(html))
doc.div(HTML(htmlstring))
htmlstring = ""
return rawhtml, doc, htmlstring
@ -52,19 +56,15 @@ def generateLines(title, lines):
doc = Document(title, lang="en")
rawhtml = False
htmlstring = ""
for line in lines:
for id, line in enumerate(lines):
#parse raw HTML
rawhtml, doc, htmlstring = parseRawHTML(doc, line, htmlstring, rawhtml)
rawhtml, doc, htmlstring = parseRawHTML(doc, line, htmlstring, rawhtml, id, len(lines))
#parse markdown
if not rawhtml:
doc = parseMarkdown(doc, line)
#if indented html was the last line, this is needed for it to not be ignored
if rawhtml:
doc.div(HTML(htmlstring))
generatePage(title, doc)
def generatePage(title, doc):