Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/highlightjs.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import functools | import functools | ||||
from typing import Dict | |||||
from pygments.lexers import ( | from pygments.lexers import ( | ||||
get_all_lexers, | get_all_lexers, | ||||
get_lexer_for_filename | get_lexer_for_filename | ||||
) | ) | ||||
# set of languages ids that can be highlighted | # set of languages ids that can be highlighted | ||||
# by highlight.js library | # by highlight.js library | ||||
_hljs_languages = set([ | _hljs_languages = set([ | ||||
▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | _hljs_languages_aliases = { | ||||
'YAML': 'yaml', | 'YAML': 'yaml', | ||||
'yml': 'yaml', | 'yml': 'yaml', | ||||
'zep': 'zephir', | 'zep': 'zephir', | ||||
'zone': 'dns', | 'zone': 'dns', | ||||
'zsh': 'bash' | 'zsh': 'bash' | ||||
} | } | ||||
# dictionary mapping pygment lexers to hljs languages | # dictionary mapping pygment lexers to hljs languages | ||||
_pygments_lexer_to_hljs_language = {} | _pygments_lexer_to_hljs_language = {} # type: Dict[str, str] | ||||
# dictionary mapping mime types to hljs languages | # dictionary mapping mime types to hljs languages | ||||
_mime_type_to_hljs_language = { | _mime_type_to_hljs_language = { | ||||
'text/x-c': 'cpp', | 'text/x-c': 'cpp', | ||||
'text/x-c++': 'cpp', | 'text/x-c++': 'cpp', | ||||
'text/x-msdos-batch': 'dos', | 'text/x-msdos-batch': 'dos', | ||||
'text/x-lisp': 'lisp', | 'text/x-lisp': 'lisp', | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |