Skip to content

Commit

Permalink
Use Pygments API
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Oct 4, 2014
1 parent f0c5b71 commit 5a44ed9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions markdown/extensions/codehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
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
Expand Down Expand Up @@ -109,14 +109,15 @@ def hilite(self):
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
Expand Down Expand Up @@ -247,4 +248,3 @@ def extendMarkdown(self, md, md_globals):

def makeExtension(*args, **kwargs):
return CodeHiliteExtension(*args, **kwargs)

0 comments on commit 5a44ed9

Please sign in to comment.