Skip to content

Commit

Permalink
markdown: Disable Codehilite language guessing
Browse files Browse the repository at this point in the history
It appears that for random text the MIME lexer wins:

    In [4]: import pygments.lexer
    In [5]: pygments.lexers.guess_lexer("Hallo")
    Out[5]: <pygments.lexers.MIMELexer>

which usually generates errors for random text:

    In [11]: from markdown.extensions.codehilite import CodeHilite
    In [12]: CodeHilite(src = 'Hallo').hilite()
    Out[12]: '<div class="codehilite"><pre><span></span><span class="err">Hallo</span>\n</pre></div>\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]: '<div class="codehilite"><pre><span></span>Hallo\n</pre></div>\n'

In Markdown, the language should be set explicitly, for language
specific highlighting.

    :::python
    print("Hallo")
  • Loading branch information
donald committed Feb 4, 2020
1 parent b3d52f6 commit 0401703
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mpicms/base/templatetags/md_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 0401703

Please sign in to comment.