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! # Welcome!
This is the homepage of our website. This is the homepage of our website.
> >
<b>Hello</b> <b>HTML Hello</b>
Another line Another markdown line
<a href=/test>**Another line 2**</a> <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): def generateNavigationBar(lines):
global navbar global navbar
navbar = E navbar = E
for line in lines: for id, line in enumerate(lines):
title, link = line.strip().split(";", 1) title, link = line.strip().split(";", 1)
navbar = navbar.li(HTML("<a href='" + link + "'>" + title + "</a>")) 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 #raw html start
if line.strip() == ">": if line.strip() == ">":
rawhtml = True rawhtml = True
@ -37,9 +37,13 @@ def parseRawHTML(doc, line, htmlstring, rawhtml):
elif rawhtml: elif rawhtml:
if line.startswith(" "): if line.startswith(" "):
htmlstring = htmlstring + line.strip() 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: else:
rawhtml = False rawhtml = False
doc.div(HTML(html)) doc.div(HTML(htmlstring))
htmlstring = "" htmlstring = ""
return rawhtml, doc, htmlstring return rawhtml, doc, htmlstring
@ -52,19 +56,15 @@ def generateLines(title, lines):
doc = Document(title, lang="en") doc = Document(title, lang="en")
rawhtml = False rawhtml = False
htmlstring = "" htmlstring = ""
for line in lines: for id, line in enumerate(lines):
#parse raw HTML #parse raw HTML
rawhtml, doc, htmlstring = parseRawHTML(doc, line, htmlstring, rawhtml) rawhtml, doc, htmlstring = parseRawHTML(doc, line, htmlstring, rawhtml, id, len(lines))
#parse markdown #parse markdown
if not rawhtml: if not rawhtml:
doc = parseMarkdown(doc, line) 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) generatePage(title, doc)
def generatePage(title, doc): def generatePage(title, doc):