Show More
@@ -446,25 +446,23 b' class FileNode(Node):' | |||
|
446 | 446 | def mimetype_main(self): |
|
447 | 447 | return self.mimetype.split('/')[0] |
|
448 | 448 | |
|
449 | @LazyProperty | |
|
450 | def lexer(self): | |
|
451 | """ | |
|
452 | Returns pygment's lexer class. Would try to guess lexer taking file's | |
|
453 | content, name and mimetype. | |
|
454 | """ | |
|
449 | @classmethod | |
|
450 | def get_lexer(cls, filename, content=None): | |
|
455 | 451 | from pygments import lexers |
|
456 | 452 | |
|
453 | extension = filename.split('.')[-1] | |
|
457 | 454 | lexer = None |
|
455 | ||
|
458 | 456 | try: |
|
459 | 457 | lexer = lexers.guess_lexer_for_filename( |
|
460 |
|
|
|
458 | filename, content, stripnl=False) | |
|
461 | 459 | except lexers.ClassNotFound: |
|
462 | 460 | lexer = None |
|
463 | 461 | |
|
464 | 462 | # try our EXTENSION_MAP |
|
465 | 463 | if not lexer: |
|
466 | 464 | try: |
|
467 |
lexer_class = LANGUAGES_EXTENSIONS_MAP.get( |
|
|
465 | lexer_class = LANGUAGES_EXTENSIONS_MAP.get(extension) | |
|
468 | 466 | if lexer_class: |
|
469 | 467 | lexer = lexers.get_lexer_by_name(lexer_class[0]) |
|
470 | 468 | except lexers.ClassNotFound: |
@@ -476,6 +474,14 b' class FileNode(Node):' | |||
|
476 | 474 | return lexer |
|
477 | 475 | |
|
478 | 476 | @LazyProperty |
|
477 | def lexer(self): | |
|
478 | """ | |
|
479 | Returns pygment's lexer class. Would try to guess lexer taking file's | |
|
480 | content, name and mimetype. | |
|
481 | """ | |
|
482 | return self.get_lexer(self.name, self.content) | |
|
483 | ||
|
484 | @LazyProperty | |
|
479 | 485 | def lexer_alias(self): |
|
480 | 486 | """ |
|
481 | 487 | Returns first alias of the lexer guessed for this file. |
General Comments 0
You need to be logged in to leave comments.
Login now