Fix pygments latest version

This commit is contained in:
cuom1999 2022-09-15 12:01:29 -05:00
parent 979b9862fb
commit 1c0686e30a

View file

@ -7,17 +7,10 @@ def _make_pre_code(code):
return mark_safe("<pre>" + escape(code) + "</pre>") return mark_safe("<pre>" + escape(code) + "</pre>")
def _wrap_code(inner):
yield 0, "<code>"
for tup in inner:
yield tup
yield 0, "</code>"
try: try:
import pygments import pygments
import pygments.lexers import pygments.lexers
import pygments.formatters.html import pygments.formatters
import pygments.util import pygments.util
except ImportError: except ImportError:
@ -25,11 +18,6 @@ except ImportError:
return _make_pre_code(code) return _make_pre_code(code)
else: else:
class HtmlCodeFormatter(pygments.formatters.HtmlFormatter):
def wrap(self, source, outfile):
return self._wrap_div(self._wrap_pre(_wrap_code(source)))
def highlight_code(code, language, cssclass="codehilite", linenos=True): def highlight_code(code, language, cssclass="codehilite", linenos=True):
try: try:
lexer = pygments.lexers.get_lexer_by_name(language) lexer = pygments.lexers.get_lexer_by_name(language)
@ -39,9 +27,9 @@ else:
if linenos: if linenos:
return mark_safe( return mark_safe(
pygments.highlight( pygments.highlight(
code, lexer, HtmlCodeFormatter(cssclass=cssclass, linenos="table") code, lexer, HtmlCodeFormatter(cssclass=cssclass, linenos="table", wrapcode=True)
) )
) )
return mark_safe( return mark_safe(
pygments.highlight(code, lexer, HtmlCodeFormatter(cssclass=cssclass)) pygments.highlight(code, lexer, HtmlCodeFormatter(cssclass=cssclass, wrapcode=True))
) )