Skip to content

Commit b66baf0

Browse files
committed
Syntax highlighting: Fix language-name parsing
1 parent 718dc05 commit b66baf0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pyqt_code_editor/syntax_highlighters/syntax_highlighter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
logging.basicConfig(level=logging.INFO, force=True)
55
logger = logging.getLogger(__name__)
66
module_cache = {}
7-
# Some lexers have names that are not recognized by get_lexer_by_name(), which
8-
# seems like an issue with pygments. To catch this, here we explicitly rename.
9-
LANGUAGE_MAP = {
10-
'javascript+genshi text': 'javascript+genshi'
11-
}
127

8+
# Some lexers have weird names that are not recognized by get_lexer_by_name().
9+
# Often this seems to be a matter of discarding a suffix after a space or /
10+
# This may not be a foolproof solution.
11+
LANGUAGE_SEPARATORS = ' ', '/'
1312

14-
def create_syntax_highlighter(language, *args, **kwargs):
15-
if language in LANGUAGE_MAP:
16-
logger.info(f'mapping {language} to {LANGUAGE_MAP[language]}')
17-
language = LANGUAGE_MAP[language]
13+
def create_syntax_highlighter(language, *args, **kwargs):
14+
for ch in LANGUAGE_SEPARATORS:
15+
if ch in language:
16+
logger.info(f'mapping {language} to {language[:language.find(ch)]}')
17+
language = language[:language.find(ch)]
1818
try:
1919
lexer = get_lexer_by_name(language)
20-
except:
20+
except Exception:
2121
lexer = get_lexer_by_name('markdown')
2222
if language not in module_cache:
2323
try:

0 commit comments

Comments
 (0)