Update misaka lib to fix (#229); and fix compatibility with pygments (#208)

Lift off setup.cfg;
replaced misaka with mistune; thanks to papoteur-mga suggestion.
Create a new formatter instance for each highlight call to avoid the pygments >= 2.12.0 issue

Signed-off-by: Darren Nathanael <github@darrennathanael.com>
This commit is contained in:
Darren Nathanael 2024-12-04 02:42:03 +07:00
parent 60cd179c18
commit afac29cd2f
No known key found for this signature in database
GPG key ID: 5D1D163C5A189F40
2 changed files with 11 additions and 11 deletions

View file

@ -1,4 +1,5 @@
from logging import getLogger
import mistune
from django.apps import apps
from django.template.defaultfilters import escape, linebreaksbr
@ -73,15 +74,12 @@ class MarkdownHighlighter(PlainTextHighlighter):
render_flags = ("skip-html",)
def highlight(self, code_string, **kwargs):
import misaka
return mark_safe(
misaka.html(
code_string,
extensions=self.extensions,
render_flags=self.render_flags,
)
"""Highlight Markdown using Mistune"""
markdown = mistune.create_markdown(
plugins=['table', 'footnotes', 'strikethrough', 'superscript',
'fenced_code', 'quote', 'url']
)
return mark_safe(markdown(code_string))
class RestructuredTextHighlighter(PlainTextHighlighter):
@ -140,7 +138,6 @@ class PygmentsHighlighter(Highlighter):
determined by the lexer name.
"""
formatter = NakedHtmlFormatter()
lexer = None
lexer_fallback = PythonLexer()
@ -152,7 +149,9 @@ class PygmentsHighlighter(Highlighter):
logger.warning("Lexer for given name %s not found", lexer_name)
self.lexer = self.lexer_fallback
return highlight(code_string, self.lexer, self.formatter)
# Create a new formatter instance for each highlight call to avoid the pygments >= 2.12.0 issue
formatter = NakedHtmlFormatter()
return highlight(code_string, self.lexer, formatter)
class SolidityHighlighter(PygmentsHighlighter):

View file

@ -30,7 +30,7 @@ python_requires = >=3.6
install_requires =
# Essential packages
django>=3.2
pygments<=2.11.2
pygments
django-staticinline>=1.0
django-csp>=3.6
dj_database_url>=0.5.0
@ -39,6 +39,7 @@ install_requires =
# Additional Lexer
jsx-lexer>=0.0.8
misaka>=2.1.0
mistune
docutils
# Testsuite