Refactored syntax highlighter code to a separate function
This commit is contained in:
parent
8766626ca7
commit
ef2791dde3
@ -22,15 +22,17 @@ class CodeFormatter(HtmlFormatter):
|
|||||||
yield i, t
|
yield i, t
|
||||||
yield 0, "</ol></pre>"
|
yield 0, "</ol></pre>"
|
||||||
|
|
||||||
|
def hilite(language, code):
|
||||||
|
lexer = get_lexer_by_name(language)
|
||||||
|
formatter = CodeFormatter(style = SolarizedDarkStyle, linenos = False, cssclass = language + " code", noclasses = True)
|
||||||
|
return highlight(code, lexer, formatter)
|
||||||
|
|
||||||
@register.filter(needs_autoescape=True)
|
@register.filter(needs_autoescape=True)
|
||||||
@stringfilter
|
@stringfilter
|
||||||
def syhilite(value, language, autoescape=None):
|
def syhilite(value, language, autoescape=None):
|
||||||
if language == "php":
|
if language == "php":
|
||||||
value = "<?php\n" + value
|
value = "<?php\n" + value
|
||||||
|
|
||||||
lexer = get_lexer_by_name(language)
|
html = hilite(language, value)
|
||||||
formatter = CodeFormatter(style = SolarizedDarkStyle, linenos = False, cssclass = language + " code", noclasses = True)
|
|
||||||
html = highlight(value, lexer, formatter)
|
|
||||||
css = formatter.get_style_defs(['.code-chunk .code'])
|
|
||||||
return mark_safe(html)
|
return mark_safe(html)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user