diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2014-10-06 21:45:43 -0400 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2014-10-06 21:45:43 -0400 |
commit | 57633f1743cc16e16c140cc92f860c62d872b6cc (patch) | |
tree | f35a0b944f85ba671372ddabf5e06258a33f26fc | |
parent | f0c5b71acbc02af60a33d67c59558bb513b25e74 (diff) | |
parent | 5a44ed959880b73561dc97212a1286d47c7d40f0 (diff) | |
download | markdown-57633f1743cc16e16c140cc92f860c62d872b6cc.tar.gz markdown-57633f1743cc16e16c140cc92f860c62d872b6cc.tar.bz2 markdown-57633f1743cc16e16c140cc92f860c62d872b6cc.zip |
Merge pull request #350 from facelessuser/master
Use Pygments API
-rw-r--r-- | markdown/extensions/codehilite.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py index 7fbf83f..0c3df7e 100644 --- a/markdown/extensions/codehilite.py +++ b/markdown/extensions/codehilite.py @@ -22,8 +22,8 @@ from ..treeprocessors import Treeprocessor import warnings try: from pygments import highlight - from pygments.lexers import get_lexer_by_name, guess_lexer, TextLexer - from pygments.formatters import HtmlFormatter + from pygments.lexers import get_lexer_by_name, guess_lexer + from pygments.formatters import get_formatter_by_name pygments = True except ImportError: pygments = False @@ -109,14 +109,15 @@ class CodeHilite(object): if self.guess_lang: lexer = guess_lexer(self.src) else: - lexer = TextLexer() + lexer = get_lexer_by_name('text') except ValueError: - lexer = TextLexer() - formatter = HtmlFormatter(linenos=self.linenums, - cssclass=self.css_class, - style=self.style, - noclasses=self.noclasses, - hl_lines=self.hl_lines) + lexer = get_lexer_by_name('text') + formatter = get_formatter_by_name('html', + linenos=self.linenums, + cssclass=self.css_class, + style=self.style, + noclasses=self.noclasses, + hl_lines=self.hl_lines) return highlight(self.src, lexer, formatter) else: # just escape and build markup usable by JS highlighting libs @@ -247,4 +248,3 @@ class CodeHiliteExtension(Extension): def makeExtension(*args, **kwargs): return CodeHiliteExtension(*args, **kwargs) - |