Tweak the html to apply classes

This commit is contained in:
Oliver Marks 2018-10-18 22:23:58 +01:00
parent e2ee303815
commit 3b0bd4bcd3
1 changed files with 15 additions and 10 deletions

View File

@ -9,26 +9,31 @@ def src(code):
return highlight(code, lexer, HtmlFormatter())
builddoc ={
"HEADER1": "h2",
"HEADER2": "h3",
"HEADER3": "h4",
"BREAK": "br",
"TEXT": "p",
"SRC_BEGIN": src,
"EXAMPLE": 'pre',
"HEADER1": ("h2", None),
"HEADER2": ("h3", None),
"HEADER3": ("h4", None),
# "BREAK": "br",
"TEXT": ("p", "flow-text"),
"SRC_BEGIN": (src, None),
"EXAMPLE": ('vblockquote', None),
}
def html(doc):
response = StringIO()
for item in doc:
tag = builddoc.get(item.token)
if not tag:
match = builddoc.get(item.token)
if not match:
continue
tag, cls = match
if cls:
cls = f' class="{cls}"'
else:
cls = ''
if callable(tag):
response.write(tag(item.value))
continue
else:
response.write('<%s>%s<%s/>\n' % (tag, item.value, tag))
response.write('<%s%s>%s<%s/>\n' % (tag, cls, item.value, tag))
response.seek(0)
return response