Show More
@@ -28,7 +28,11 b' from rhodecode.lib.utils2 import __get_l' | |||
|
28 | 28 | |
|
29 | 29 | # language map is also used by whoosh indexer, which for those specified |
|
30 | 30 | # extensions will index it's content |
|
31 | LANGUAGES_EXTENSIONS_MAP = __get_lem() | |
|
31 | # custom extensions to lexers, format is 'ext': 'LexerClass' | |
|
32 | extra = { | |
|
33 | 'vbs': 'VbNet' | |
|
34 | } | |
|
35 | LANGUAGES_EXTENSIONS_MAP = __get_lem(extra) | |
|
32 | 36 | |
|
33 | 37 | DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" |
|
34 | 38 |
@@ -48,12 +48,12 b' def annotate_highlight(' | |||
|
48 | 48 | :param headers: dictionary with headers (keys are whats in ``order`` |
|
49 | 49 | parameter) |
|
50 | 50 | """ |
|
51 |
from rhodecode.lib. |
|
|
51 | from rhodecode.lib.helpers import get_lexer_for_filenode | |
|
52 | 52 | options['linenos'] = True |
|
53 | 53 | formatter = AnnotateHtmlFormatter( |
|
54 | 54 | filenode=filenode, order=order, headers=headers, |
|
55 | 55 | annotate_from_commit_func=annotate_from_commit_func, **options) |
|
56 | lexer = get_custom_lexer(filenode.extension) or filenode.lexer | |
|
56 | lexer = get_lexer_for_filenode(filenode) | |
|
57 | 57 | highlighted = highlight(filenode.content, lexer, formatter) |
|
58 | 58 | return highlighted |
|
59 | 59 |
@@ -520,13 +520,18 b' def get_lexer_safe(mimetype=None, filepa' | |||
|
520 | 520 | return lexer |
|
521 | 521 | |
|
522 | 522 | |
|
523 | def get_lexer_for_filenode(filenode): | |
|
524 | lexer = get_custom_lexer(filenode.extension) or filenode.lexer | |
|
525 | return lexer | |
|
526 | ||
|
527 | ||
|
523 | 528 | def pygmentize(filenode, **kwargs): |
|
524 | 529 | """ |
|
525 | 530 | pygmentize function using pygments |
|
526 | 531 | |
|
527 | 532 | :param filenode: |
|
528 | 533 | """ |
|
529 | lexer = get_custom_lexer(filenode.extension) or filenode.lexer | |
|
534 | lexer = get_lexer_for_filenode(filenode) | |
|
530 | 535 | return literal(code_highlight(filenode.content, lexer, |
|
531 | 536 | CodeHtmlFormatter(**kwargs))) |
|
532 | 537 |
@@ -54,7 +54,7 b' def md5_safe(s):' | |||
|
54 | 54 | return md5(safe_str(s)) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | def __get_lem(): | |
|
57 | def __get_lem(extra_mapping=None): | |
|
58 | 58 | """ |
|
59 | 59 | Get language extension map based on what's inside pygments lexers |
|
60 | 60 | """ |
@@ -82,7 +82,16 b' def __get_lem():' | |||
|
82 | 82 | desc = lx.replace('Lexer', '') |
|
83 | 83 | d[ext].append(desc) |
|
84 | 84 | |
|
85 |
|
|
|
85 | data = dict(d) | |
|
86 | ||
|
87 | extra_mapping = extra_mapping or {} | |
|
88 | if extra_mapping: | |
|
89 | for k, v in extra_mapping.items(): | |
|
90 | if k not in data: | |
|
91 | # register new mapping2lexer | |
|
92 | data[k] = [v] | |
|
93 | ||
|
94 | return data | |
|
86 | 95 | |
|
87 | 96 | |
|
88 | 97 | def str2bool(_str): |
@@ -110,7 +119,7 b' def aslist(obj, sep=None, strip=True):' | |||
|
110 | 119 | :param sep: |
|
111 | 120 | :param strip: |
|
112 | 121 | """ |
|
113 | if isinstance(obj, (basestring)): | |
|
122 | if isinstance(obj, (basestring,)): | |
|
114 | 123 | lst = obj.split(sep) |
|
115 | 124 | if strip: |
|
116 | 125 | lst = [v.strip() for v in lst] |
@@ -27,6 +27,7 b' import stat' | |||
|
27 | 27 | |
|
28 | 28 | from zope.cachedescriptors.property import Lazy as LazyProperty |
|
29 | 29 | |
|
30 | from rhodecode.config.conf import LANGUAGES_EXTENSIONS_MAP | |
|
30 | 31 | from rhodecode.lib.utils import safe_unicode, safe_str |
|
31 | 32 | from rhodecode.lib.utils2 import md5 |
|
32 | 33 | from rhodecode.lib.vcs import path as vcspath |
@@ -435,11 +436,26 b' class FileNode(Node):' | |||
|
435 | 436 | content, name and mimetype. |
|
436 | 437 | """ |
|
437 | 438 | from pygments import lexers |
|
439 | ||
|
440 | lexer = None | |
|
438 | 441 | try: |
|
439 |
lexer = lexers.guess_lexer_for_filename( |
|
|
442 | lexer = lexers.guess_lexer_for_filename( | |
|
443 | self.name, self.content, stripnl=False) | |
|
440 | 444 | except lexers.ClassNotFound: |
|
445 | lexer = None | |
|
446 | ||
|
447 | # try our EXTENSION_MAP | |
|
448 | if not lexer: | |
|
449 | try: | |
|
450 | lexer_class = LANGUAGES_EXTENSIONS_MAP.get(self.extension) | |
|
451 | if lexer_class: | |
|
452 | lexer = lexers.get_lexer_by_name(lexer_class[0]) | |
|
453 | except lexers.ClassNotFound: | |
|
454 | lexer = None | |
|
455 | ||
|
456 | if not lexer: | |
|
441 | 457 | lexer = lexers.TextLexer(stripnl=False) |
|
442 | # returns first alias | |
|
458 | ||
|
443 | 459 | return lexer |
|
444 | 460 | |
|
445 | 461 | @LazyProperty |
@@ -5,7 +5,8 b'' | |||
|
5 | 5 | <span> <strong>${c.file}</strong></span> |
|
6 | 6 | <span> | ${c.file.lines()[0]} ${ungettext('line', 'lines', c.file.lines()[0])}</span> |
|
7 | 7 | <span> | ${h.format_byte_size_binary(c.file.size)}</span> |
|
8 |
<span |
|
|
8 | <span> | ${c.file.mimetype} </span> | |
|
9 | <span class="item last"> | ${h.get_lexer_for_filenode(c.file).__class__.__name__}</span> | |
|
9 | 10 | </div> |
|
10 | 11 | <div class="buttons"> |
|
11 | 12 | <a id="file_history_overview" href="#"> |
General Comments 0
You need to be logged in to leave comments.
Login now