浏览代码

Fix lexer selection a bit.

tags/v1.0^2
Ben Kurtovic 10 年前
父节点
当前提交
ab163f6b3d
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. +3
    -2
      bitshift/codelet.py

+ 3
- 2
bitshift/codelet.py 查看文件

@@ -1,7 +1,7 @@
from operator import concat

from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.lexers import find_lexer_class, get_lexer_by_name
from pygments.formatters.html import HtmlFormatter

from .languages import LANGS
@@ -88,11 +88,12 @@ class Codelet(object):
lang = LANGS[self.language]
code = self.code
if highlight_code:
lexer = find_lexer_class(lang) or get_lexer_by_name("text")
symbols = reduce(concat, self.symbols.values(), [])
lines = reduce(concat, [[loc[0] for loc in sym[1] + sym[2]]
for sym in symbols], [])
formatter = HtmlFormatter(linenos=True, hl_lines=lines)
code = highlight(code, get_lexer_by_name(lang.lower()), formatter)
code = highlight(code, lexer, formatter)

return {
"name": self.name, "code": code, "lang": lang,


正在加载...
取消
保存