escape HTML in markdown, more functions
This commit is contained in:
parent
bdb6422612
commit
16fb70aaeb
@ -3,4 +3,4 @@ This is the homepage of our website.
|
||||
>
|
||||
<b>Hello</b>
|
||||
Another line
|
||||
Another line 2
|
||||
<a href=/test>**Another line 2**</a>
|
||||
|
45
generate.py
45
generate.py
@ -2,6 +2,7 @@ import os
|
||||
from html5tagger import Document, E, HTML
|
||||
from shutil import rmtree
|
||||
import markdown
|
||||
import html
|
||||
|
||||
#if homepage is at Home.page, set homepage to "Home"
|
||||
homepage = "Home"
|
||||
@ -26,33 +27,43 @@ def generateNavigationBar(lines):
|
||||
title, link = line.strip().split(";", 1)
|
||||
navbar = navbar.li(HTML("<a href='" + link + "'>" + title + "</a>"))
|
||||
|
||||
def parseRawHTML(doc, line, htmlstring, rawhtml):
|
||||
#raw html start
|
||||
if line.strip() == ">":
|
||||
rawhtml = True
|
||||
htmlstring = ""
|
||||
|
||||
#parse indented raw html
|
||||
elif rawhtml:
|
||||
if line.startswith(" "):
|
||||
htmlstring = htmlstring + line.strip()
|
||||
else:
|
||||
rawhtml = False
|
||||
doc.div(HTML(html))
|
||||
htmlstring = ""
|
||||
return rawhtml, doc, htmlstring
|
||||
|
||||
def parseMarkdown(doc, line):
|
||||
line = html.escape(line.strip())
|
||||
return doc(HTML(markdown.markdown(line)))
|
||||
|
||||
def generateLines(title, lines):
|
||||
title = title.replace(".page", "")
|
||||
doc = Document(title, lang="en")
|
||||
rawhtml = False
|
||||
htmlstring = ""
|
||||
for line in lines:
|
||||
|
||||
#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
|
||||
doc.div(HTML(html))
|
||||
#parse raw HTML
|
||||
rawhtml, doc, htmlstring = parseRawHTML(doc, line, htmlstring, rawhtml)
|
||||
|
||||
#parse markdown
|
||||
if rawhtml == False:
|
||||
doc(HTML( markdown.markdown(line.strip()) ))
|
||||
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 == True:
|
||||
rawhtml = False
|
||||
doc.div(HTML(html))
|
||||
if rawhtml:
|
||||
doc.div(HTML(htmlstring))
|
||||
|
||||
generatePage(title, doc)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user