django-orchestra-test/orchestra/admin/html.py

21 lines
778 B
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django.utils.safestring import mark_safe
MONOSPACE_FONTS = ('Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,'
'Bitstream Vera Sans Mono,Courier New,monospace')
def monospace_format(text):
2016-03-11 12:19:34 +00:00
style="font-family:%s;padding-left:110px;white-space:pre-wrap;" % MONOSPACE_FONTS
2014-05-08 16:59:35 +00:00
return mark_safe('<pre style="%s">%s</pre>' % (style, text))
2015-06-22 14:14:16 +00:00
def code_format(text, language='bash'):
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
lexer = get_lexer_by_name(language, stripall=True)
formatter = HtmlFormatter(linenos=True)
code = highlight(text, lexer, formatter)
return mark_safe('<div style="padding-left:110px;">%s</div>' % code)