Handle language highlighting.
This commit is contained in:
parent
0eee46b2ae
commit
9089acfdaa
|
@ -6,22 +6,22 @@ from pygments.lexers import get_lexer_by_name
|
|||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
def src(doc, code, cls=''):
|
||||
lexer = get_lexer_by_name('lisp')
|
||||
return highlight(code, lexer, HtmlFormatter())
|
||||
lexer = get_lexer_by_name(code.attrs.get('language', 'shell'))
|
||||
return highlight(code.value, lexer, HtmlFormatter())
|
||||
|
||||
def img(doc, item, cls=''):
|
||||
caption = doc.previous('CAPTION')
|
||||
text = ''
|
||||
if caption:
|
||||
text = f'<p class="center-align">{caption.value}</p>'
|
||||
return f'<img{cls} style="margin:auto;" src="{item[0]}" alt="{item[1]}" />{text}'
|
||||
return f'<img{cls} style="margin:auto;" src="{item.value[0]}" alt="{item.value[1]}" />{text}'
|
||||
|
||||
|
||||
def parse_text_html(doc, tokens, cls=''):
|
||||
if isinstance(tokens, list):
|
||||
for token in tokens:
|
||||
return handle_token(doc, token)
|
||||
return f'<p{cls}>{tokens}</p>'
|
||||
def parse_text_html(doc, token, cls=''):
|
||||
if isinstance(token.value, list):
|
||||
for item in token.value:
|
||||
return handle_token(doc, item)
|
||||
return f'<p{cls}>{token.value}</p>'
|
||||
|
||||
builddoc ={
|
||||
"HEADER1": ("h2", None),
|
||||
|
@ -48,7 +48,7 @@ def handle_token(doc, item):
|
|||
else:
|
||||
cls = ''
|
||||
if callable(tag):
|
||||
return tag(doc, item.value, cls)
|
||||
return tag(doc, item, cls)
|
||||
else:
|
||||
return '<%s%s>%s</%s>\n' % (tag, cls, item.value, tag)
|
||||
|
||||
|
|
Loading…
Reference in New Issue