Browse Source

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.
merge-requests/57/head
Petr Stastny 7 years ago
parent
commit
0e377b2634
  1. 5
      tildes/tildes/lib/markdown.py

5
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 <?php ... ?> 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

Loading…
Cancel
Save