def _format_code(html_code):
# syntax highlighting:
code_highlighted = highlight(html_code, HtmlLexer(), HtmlFormatter(style='monokai', noclasses=True))
# add formatting for diff-markers:
common_diff_style = ' margin-right: 3px; padding-right: 7px; padding-left: 7px;'
code_formatted = code_highlighted \
.replace('[-', '<span style="background: #71332c;' + common_diff_style + '">') \
.replace('-]', '</span>') \
.replace('{+', '<span style="background: #2e4d28;' + common_diff_style + '">') \
.replace('+}', '</span>')
# wrap in general layout:
code_wrapped = '<div style="color: #efefef; margin: 3px; margin-left: 17px;line-height: 150%%;">%s</div>'\
%(code_formatted)
return code_wrapped
评论列表
文章目录