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