mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-23 15:13:06 +11:00
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:
parent
60cd179c18
commit
afac29cd2f
2 changed files with 11 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
import mistune
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.template.defaultfilters import escape, linebreaksbr
|
from django.template.defaultfilters import escape, linebreaksbr
|
||||||
|
@ -73,15 +74,12 @@ class MarkdownHighlighter(PlainTextHighlighter):
|
||||||
render_flags = ("skip-html",)
|
render_flags = ("skip-html",)
|
||||||
|
|
||||||
def highlight(self, code_string, **kwargs):
|
def highlight(self, code_string, **kwargs):
|
||||||
import misaka
|
"""Highlight Markdown using Mistune"""
|
||||||
|
markdown = mistune.create_markdown(
|
||||||
return mark_safe(
|
plugins=['table', 'footnotes', 'strikethrough', 'superscript',
|
||||||
misaka.html(
|
'fenced_code', 'quote', 'url']
|
||||||
code_string,
|
|
||||||
extensions=self.extensions,
|
|
||||||
render_flags=self.render_flags,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
return mark_safe(markdown(code_string))
|
||||||
|
|
||||||
|
|
||||||
class RestructuredTextHighlighter(PlainTextHighlighter):
|
class RestructuredTextHighlighter(PlainTextHighlighter):
|
||||||
|
@ -140,7 +138,6 @@ class PygmentsHighlighter(Highlighter):
|
||||||
determined by the lexer name.
|
determined by the lexer name.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
formatter = NakedHtmlFormatter()
|
|
||||||
lexer = None
|
lexer = None
|
||||||
lexer_fallback = PythonLexer()
|
lexer_fallback = PythonLexer()
|
||||||
|
|
||||||
|
@ -152,7 +149,9 @@ class PygmentsHighlighter(Highlighter):
|
||||||
logger.warning("Lexer for given name %s not found", lexer_name)
|
logger.warning("Lexer for given name %s not found", lexer_name)
|
||||||
self.lexer = self.lexer_fallback
|
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):
|
class SolidityHighlighter(PygmentsHighlighter):
|
||||||
|
|
|
@ -30,7 +30,7 @@ python_requires = >=3.6
|
||||||
install_requires =
|
install_requires =
|
||||||
# Essential packages
|
# Essential packages
|
||||||
django>=3.2
|
django>=3.2
|
||||||
pygments<=2.11.2
|
pygments
|
||||||
django-staticinline>=1.0
|
django-staticinline>=1.0
|
||||||
django-csp>=3.6
|
django-csp>=3.6
|
||||||
dj_database_url>=0.5.0
|
dj_database_url>=0.5.0
|
||||||
|
@ -39,6 +39,7 @@ install_requires =
|
||||||
# Additional Lexer
|
# Additional Lexer
|
||||||
jsx-lexer>=0.0.8
|
jsx-lexer>=0.0.8
|
||||||
misaka>=2.1.0
|
misaka>=2.1.0
|
||||||
|
mistune
|
||||||
docutils
|
docutils
|
||||||
|
|
||||||
# Testsuite
|
# Testsuite
|
||||||
|
|
Loading…
Reference in a new issue