From 0401703936f10a111c0937ec5d285af6754b50c3 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 4 Feb 2020 17:13:42 +0100 Subject: [PATCH] markdown: Disable Codehilite language guessing It appears that for random text the MIME lexer wins: In [4]: import pygments.lexer In [5]: pygments.lexers.guess_lexer("Hallo") Out[5]: which usually generates errors for random text: In [11]: from markdown.extensions.codehilite import CodeHilite In [12]: CodeHilite(src = 'Hallo').hilite() Out[12]: '
Hallo\n
\n' which just look ugly (red border on each line). So switch off language guessing. In that case, code blocks without a explicit language are left as is: In [13]: CodeHilite(src = 'Hallo',guess_lang=False).hilite() Out[13]: '
Hallo\n
\n' In Markdown, the language should be set explicitly, for language specific highlighting. :::python print("Hallo") --- mpicms/base/templatetags/md_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpicms/base/templatetags/md_tags.py b/mpicms/base/templatetags/md_tags.py index 1742044..7cc51ec 100644 --- a/mpicms/base/templatetags/md_tags.py +++ b/mpicms/base/templatetags/md_tags.py @@ -19,7 +19,7 @@ def markdown(text): md_processor = md_module.Markdown( extensions=[ ExtraExtension(), - CodeHiliteExtension(), + CodeHiliteExtension(guess_lang=False), Nl2BrExtension(), SaneListExtension(), SmartyExtension(smart_angled_quotes=True),