Basic markdown and raw HTML support

This commit is contained in:
Govindas 2022-01-24 12:09:04 +02:00
parent 1e02f03a0f
commit 4fc7dd18c0
2 changed files with 28 additions and 3 deletions

View File

@ -1,2 +1,4 @@
Welcome! # Welcome!
This is the homepage of our website. This is the homepage of our website.
>
<b>Hello</b>

View File

@ -1,6 +1,7 @@
import os import os
from html5tagger import Document, E, HTML from html5tagger import Document, E, HTML
from shutil import rmtree from shutil import rmtree
import markdown
#if homepage is at Home.page, set homepage to "Home" #if homepage is at Home.page, set homepage to "Home"
homepage = "Home" homepage = "Home"
@ -27,9 +28,31 @@ def generateNavigationBar(lines):
def generateLines(title, lines): def generateLines(title, lines):
title = title.replace(".page", "") title = title.replace(".page", "")
document = Document(title, lang="en") document = Document(title, lang="en")
rawhtml = False
for line in lines: for line in lines:
document.p(line.strip())
#raw html start
if line.strip() == ">":
rawhtml = True
html = ""
#parse indented raw html
elif rawhtml == True:
if line.startswith(" "):
html = html + line.strip()
else:
rawhtml = False
document.join(HTML(html))
#parse markdown
else:
md = markdown.markdown(line.strip())
document.join(HTML(md))
#if indented html was the last line, this is needed for it to not be ignored
if rawhtml == True:
rawhtml = False
document.join(HTML(html))
generatePage(title, document) generatePage(title, document)