本文整理汇总了Python中pygments.lexers.get_all_lexers函数的典型用法代码示例。如果您正苦于以下问题:Python get_all_lexers函数的具体用法?Python get_all_lexers怎么用?Python get_all_lexers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_all_lexers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
def get_context_data(self, **kwargs):
context = super(SyntaxView, self).get_context_data(**kwargs)
context['syntax_list'] = sorted(
[(i[1][0], i[0]) for i in get_all_lexers()] +
[('rrst', 'Restructured Text (Rendered)'),
('md', 'Markdown (Rendered)')])
return context
示例2: index
def index():
contenttypes = [
'text/x-bepasty-redirect', # redirect / link shortener service
]
for lexer_info in get_all_lexers():
contenttypes.extend(lexer_info[3])
return render_template('index.html', contenttypes=contenttypes)
示例3: _get_pygments_lexers
def _get_pygments_lexers(add_empty=True):
r = {}
if add_empty:
r[""] = ""
for lexer in get_all_lexers():
r[lexer[1][0]] = lexer[0]
return r
示例4: __init__
def __init__(self, parent):
Gtk.Dialog.__init__(self, "Insert code", parent, 0, use_header_bar=True,
buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
self.set_modal(True)
self.set_default_size(500, 350)
cancel_button = self.get_header_bar().get_children()[0]
self.set_focus(cancel_button)
ok_button = self.get_header_bar().get_children()[1]
ok_button.set_name("Insert")
ok_button.get_style_context().add_class("suggested-action")
box = self.get_content_area()
combobox = Gtk.ComboBoxText.new_with_entry()
combobox_entry = combobox.get_child()
completion = Gtk.EntryCompletion()
completion.set_model(combobox.get_model())
completion.set_text_column(0)
combobox_entry.set_completion(completion)
combobox_entry.set_placeholder_text("Select language")
# Fill combobox with languages
for item in get_all_lexers():
combobox.append(item[1][0], item[0])
box.add(combobox)
textview = Gtk.TextView()
textview.props.expand = True
box.add(textview)
self.show_all()
示例5: lexerlist
def lexerlist(with_fnames=False):
lst = list(lexers.get_all_lexers()) + [("ANSI", ["ansi"], [], None)]
for name, aliases, fnames, _ in sorted(lst):
if with_fnames:
yield aliases, fnames
else:
yield aliases[0], name
示例6: load_lexers
def load_lexers():
global lexers
# load available pygments lexers
lexers = []
try:
global get_lexer_by_name
from pygments.lexers import get_lexer_by_name
global highlight
from pygments import highlight
global Terminal256Formatter
from pygments.formatters import Terminal256Formatter
global TerminalFormatter
from pygments.formatters import TerminalFormatter
from pygments.lexers import get_all_lexers
except ImportError:
logging.warning("the pygments module has not been found, syntax coloring is not available")
pass
else:
for lexer in get_all_lexers():
try:
lexers.append(lexer[1][0])
except IndexError:
logging.warning("cannot load lexer: %s" % lexer[0])
pass
else:
logging.debug("loaded lexer %s" % lexer[1][0])
lexers.sort()
示例7: index
def index():
from flask import render_template
contenttypes = []
for lexer_info in get_all_lexers():
contenttypes.extend(lexer_info[3])
return render_template('index.html',
contenttypes=contenttypes)
示例8: lexers
def lexers():
"""
Return the list of the pigments lexers.
"""
result = [(lexer[0], lexer[1][0]) for lexer in get_all_lexers()]
result.sort()
return result
示例9: get_all_languages
def get_all_languages():
all_languages = ['none']
for lexers in get_all_lexers():
all_languages.extend(lexers[1])
return all_languages
示例10: __init__
def __init__(self, lexers):
"""
Constructor
@param lexers reference to the lexers dictionary
"""
super(EditorHighlightersPage, self).__init__()
self.setupUi(self)
self.setObjectName("EditorHighlightersPage")
self.editorLexerList.headerItem().setText(self.editorLexerList.columnCount(), "")
header = self.editorLexerList.header()
if qVersion() >= "5.0.0":
header.setSectionResizeMode(QHeaderView.ResizeToContents)
else:
header.setResizeMode(QHeaderView.ResizeToContents)
header.setSortIndicator(0, Qt.AscendingOrder)
try:
self.extsep = os.extsep
except AttributeError:
self.extsep = "."
self.extras = ["-----------", self.tr("Alternative")]
languages = [""] + sorted(lexers.keys()) + self.extras
self.editorLexerCombo.addItems(languages)
pygmentsLexers = [""] + sorted([l[0] for l in get_all_lexers()])
self.pygmentsLexerCombo.addItems(pygmentsLexers)
# set initial values
lexerAssocs = Preferences.getEditorLexerAssocs()
for ext in lexerAssocs:
QTreeWidgetItem(self.editorLexerList, [ext, lexerAssocs[ext]])
self.editorLexerList.sortByColumn(0, Qt.AscendingOrder)
示例11: __init__
def __init__(self, *args, **kwargs):
kwargs['initial'] = dict(kwargs.get('initial', {}), language='cpp')
super(HighlighterForm, self).__init__(*args, **kwargs)
choices = []
for name, aliases, filetypes, mimetypes in get_all_lexers():
choices.append((aliases[0], name))
self.fields['language'].choices = choices
示例12: index
def index():
code = request.form.get('code', "print 'hello world!'")
lexer = (
request.form.get('lexer', '') or
unquote(request.cookies.get('lexer', 'python')))
lexers = [(l[1][0], l[0]) for l in get_all_lexers()]
lexers = sorted(lexers, lambda a, b: cmp(a[1].lower(), b[1].lower()))
style = (
request.form.get('style', '') or
unquote(request.cookies.get('style', 'colorful')))
styles = sorted(get_all_styles(), key=str.lower)
linenos = (
request.form.get('linenos', '') or
request.method == 'GET' and
unquote(request.cookies.get('linenos', ''))) or ''
divstyles = request.form.get(
'divstyles', unquote(request.cookies.get('divstyles', '')))
divstyles = divstyles or get_default_style()
html = hilite_me(code, lexer, {}, style, linenos, divstyles)
response = make_response(render_template('index.html', **locals()))
next_year = datetime.datetime.now() + datetime.timedelta(days=365)
response.set_cookie('lexer', quote(lexer), expires=next_year)
response.set_cookie('style', quote(style), expires=next_year)
response.set_cookie('linenos', quote(linenos), expires=next_year)
response.set_cookie('divstyles', quote(divstyles), expires=next_year)
return response
示例13: __init__
def __init__(self, lexers):
"""
Constructor
@param lexers reference to the lexers dictionary
"""
ConfigurationPageBase.__init__(self)
self.setupUi(self)
self.setObjectName("EditorHighlightersPage")
self.editorLexerList.headerItem().setText(self.editorLexerList.columnCount(), "")
header = self.editorLexerList.header()
header.setResizeMode(QHeaderView.ResizeToContents)
header.setSortIndicator(0, Qt.AscendingOrder)
try:
self.extsep = os.extsep
except AttributeError:
self.extsep = "."
self.extras = ["-----------", self.trUtf8("Alternative")]
languages = [''] + sorted(lexers.keys()) + self.extras
for lang in languages:
self.editorLexerCombo.addItem(lang)
pygmentsLexers = [''] + sorted([l[0] for l in get_all_lexers()])
for pygmentsLexer in pygmentsLexers:
self.pygmentsLexerCombo.addItem(pygmentsLexer)
# set initial values
lexerAssocs = Preferences.getEditorLexerAssocs()
for ext in lexerAssocs.keys():
QTreeWidgetItem(self.editorLexerList,
QStringList() << ext << lexerAssocs[ext])
self.editorLexerList.sortByColumn(0, Qt.AscendingOrder)
示例14: _lexer_alias_name_map
def _lexer_alias_name_map(self):
lexer_alias_name_map = {}
for lexer_name, aliases, _, _ in get_all_lexers():
name = aliases[0] if aliases else lexer_name
for alias in aliases:
lexer_alias_name_map[alias] = name
return lexer_alias_name_map
示例15: get_legal_pygments_lexers
def get_legal_pygments_lexers():
from pygments.lexers import get_all_lexers
lexers = []
for classname, names, dummy, dymmy in list(get_all_lexers()):
for name in names:
lexers.append(name)
return lexers