From 1319e9967a8f02d44f014c6894ef0cf529f14656 Mon Sep 17 00:00:00 2001 From: Govindas Date: Mon, 24 Jan 2022 15:20:08 +0200 Subject: [PATCH] Better parseRawHTML function --- Home.page | 9 ++++++--- generate.py | 18 +++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Home.page b/Home.page index f21e6a8..294ec26 100644 --- a/Home.page +++ b/Home.page @@ -1,6 +1,9 @@ # Welcome! This is the homepage of our website. > - Hello -Another line -**Another line 2** + HTML Hello +Another markdown line +**Another markdown line 2** +> +

**HTML Italics test 1** +

HTML Italics test 2 diff --git a/generate.py b/generate.py index 20c53b5..0c70f70 100644 --- a/generate.py +++ b/generate.py @@ -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("" + title + "")) -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):