From 0e377b26343f5aab796b03cff71c9aca6f85533f Mon Sep 17 00:00:00 2001 From: Petr Stastny Date: Wed, 20 Feb 2019 16:05:13 +0100 Subject: [PATCH] Changed way the default syntax highlighting lexer is overridden for PHP Instead of using hardcoded list of language codes that trigger the PHP lexer, an `isinstance` is now used. If Pygments decide to use PhpLexer, we detect it using isinstance and use our own PhpLexer instead. --- tildes/tildes/lib/markdown.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tildes/tildes/lib/markdown.py b/tildes/tildes/lib/markdown.py index e1f860f..f600351 100644 --- a/tildes/tildes/lib/markdown.py +++ b/tildes/tildes/lib/markdown.py @@ -206,13 +206,12 @@ def apply_syntax_highlighting(html: str) -> str: language = code_block["class"][0].replace("language-", "") try: + lexer = get_lexer_by_name(language) # If target language is PHP, override default lexer construction # and set startinline to True, so even code that is not enclosed # inside will get highlighted. - if language in ["php", "php3", "php4", "php5"]: + if isinstance(lexer, PhpLexer): lexer = PhpLexer(startinline=True) - else: - lexer = get_lexer_by_name(language) except ClassNotFound: continue