本文整理汇总了Python中pygments.styles.get_all_styles函数的典型用法代码示例。如果您正苦于以下问题:Python get_all_styles函数的具体用法?Python get_all_styles怎么用?Python get_all_styles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_all_styles函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, scheme=None, **options):
if not PYGMENTS:
raise CommandError('Unable to load pygments. '
'Please install pygments to use this command.')
if options['all_styles']:
for scheme in get_all_styles():
print HtmlFormatter(style=scheme)\
.get_style_defs('.%s .codehilite' % scheme)
# generated all styles, done and done
sys.exit(0)
if not scheme:
print """
Usage: ./manage.py pygments_styles <scheme_name>
Available color schemes:
""" + '\n'.join([" %s" % name for name in get_all_styles()])
else:
try:
assert(scheme in list(get_all_styles()))
except AssertionError:
raise CommandError('Invalid scheme name "% s"\n' % scheme +
'Please use one of the available color'
' schemes on your system:\n' +
'\n'.join([" %s" % name for name in \
get_all_styles()]))
print HtmlFormatter(style=scheme).get_style_defs('.codehilite')
sys.exit(0)
示例2: 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
示例3: _discover_styles
def _discover_styles():
import inspect
from pygments.styles import get_all_styles, get_style_by_name
# maps style 'name' (not the class name) and aliases to (module, classname) tuples
default_names = {}
names = {}
styles = {"names": names}
if DEBUG:
from collections import defaultdict
duplicates = defaultdict(set)
for name in get_all_styles():
cls = get_style_by_name(name)
mod = inspect.getmodule(cls)
val = (mod.__name__, cls.__name__)
if DEBUG and name in names and names[name] != val and name not in default_names:
duplicates[name].add(val)
duplicates[name].add(names[name])
names[name] = val
# remove some ambiquity
names.update(default_names)
# print dumplicate message
if DEBUG:
_print_duplicate_message(duplicates)
return styles
示例4: get_all_code_styles
def get_all_code_styles():
"""
Return a mapping from style names to their classes.
"""
result = dict((name, get_style_by_name(name).styles) for name in get_all_styles())
result['win32'] = win32_code_style
return result
示例5: __init__
def __init__(self, parser_state, outdir,
line_numbers=True,
formatter_style='default'):
self.state = parser_state # expect parser.ParserState instance
self.outdir = outdir
self.line_numbers = line_numbers
self.formatter_style = formatter_style
if not formatter_style in get_all_styles():
raise CheckfortException("Invalid HtmlFormatter style - " + style)
# vars to supply to all HTML templates
self.default_context = {
"to_root": "",
"gen_date": strftime("%a, %d %b %Y %H:%M:%S", gmtime()),
"project_url": project_url,
}
# default args for pygments.formatters.HtmlFormatter
self.fmt_args = {
"lineanchors": "line",
"cssclass": "highlight",
"style": formatter_style,
}
if self.line_numbers:
self.fmt_args["linenos"] = "inline"
# cache Event instances
self.events = [
Event(code, self.state.event_message[code], count)
for code, count in sorted(self.state.event_counter.iteritems(),
key=itemgetter(1), reverse=True)]
示例6: style_info
def style_info(request, response, function_info):
"""
Listet alle Stylesheet-Namen auf und zwigt die jeweiligen Styles an.
"""
style_list = list(get_all_styles())
selected_style = None
if function_info!=None:
selected_style = function_info[0]
if not selected_style in style_list:
self.page_msg.red("Name Error!")
selected_style = None
context = {
"styles": style_list,
"selected_style": selected_style,
"menu_link": request.URLs.actionLink("menu"),
}
request.templates.write("pygments_css", context, debug=False)
if selected_style == None:
# Es wurde kein Style ausgewählt
return
# CSS zum Style anzeigen
stylesheet = HtmlFormatter(style=selected_style)
stylesheet = stylesheet.get_style_defs('.pygments_code')
request.render.highlight(
".css", stylesheet, pygments_style=selected_style
)
示例7: register_options
def register_options(cls, register):
register('--code-style', choices=list(get_all_styles()), default='friendly',
help='Use this stylesheet for code highlights.')
register('--open', action='store_true',
help='Open the generated documents in a browser.')
register('--fragment', action='store_true',
help='Generate a fragment of html to embed in a page.')
示例8: highlight_
def highlight_(data, lang):
"""A helper function for highlighting data with pygments."""
try:
from pygments import highlight
from pygments.util import ClassNotFound
from pygments.styles import get_all_styles
from pygments.lexers import get_lexer_by_name
from pygments.formatters import Terminal256Formatter
except ImportError:
echo_error('Pygments is missing')
click.echo('Syntax highlighting is provided by pygments.')
click.echo('Please install pygments (http://pygments.org)!')
exit(1)
try:
lexer = get_lexer_by_name(lang)
except ClassNotFound:
echo_error('Lexer not found!')
exit(1)
try:
formatter = Terminal256Formatter(style=config.PYGMENTS_THEME)
except ClassNotFound:
styles = get_all_styles()
error_msg = 'Pygments theme {} not found!'.format(config.PYGMENTS_THEME)
echo_error(error_msg)
click.echo("Please correct pygments_theme in your '~/.noterc'!")
click.echo('Supported themes are:')
click.echo()
click.echo('\n'.join(styles))
exit(1)
return highlight(data, lexer, formatter)
示例9: load_settings
def load_settings(self):
'''This function loads project settings
'''
self.config_parser = ConfigParser(name='DesignerSettings')
DESIGNER_CONFIG = os.path.join(get_config_dir(),
constants.DESIGNER_CONFIG_FILE_NAME)
DEFAULT_CONFIG = os.path.join(get_kd_dir(),
constants.DESIGNER_CONFIG_FILE_NAME)
if not os.path.exists(DESIGNER_CONFIG):
shutil.copyfile(DEFAULT_CONFIG,
DESIGNER_CONFIG)
self.config_parser.read(DESIGNER_CONFIG)
self.config_parser.upgrade(DEFAULT_CONFIG)
# creates a panel before insert it to update code input theme list
panel = self.create_json_panel('Kivy Designer Settings',
self.config_parser,
os.path.join(get_kd_data_dir(),
'settings', 'designer_settings.json'))
uid = panel.uid
if self.interface is not None:
self.interface.add_panel(panel, 'Kivy Designer Settings', uid)
# loads available themes
for child in panel.children:
if child.id == 'code_input_theme_options':
child.items = styles.get_all_styles()
# tries to find python and buildozer path if it's not defined
path = self.config_parser.getdefault(
'global', 'python_shell_path', '')
if path.strip() == '':
self.config_parser.set('global', 'python_shell_path',
sys.executable)
self.config_parser.write()
buildozer_path = self.config_parser.getdefault('buildozer',
'buildozer_path', '')
if buildozer_path.strip() == '':
buildozer_path = find_executable('buildozer')
if buildozer_path:
self.config_parser.set('buildozer',
'buildozer_path',
buildozer_path)
self.config_parser.write()
self.add_json_panel('Buildozer', self.config_parser,
os.path.join(get_kd_data_dir(), 'settings',
'buildozer_settings.json'))
self.add_json_panel('Hanga', self.config_parser,
os.path.join(get_kd_data_dir(), 'settings',
'hanga_settings.json'))
self.add_json_panel('Keyboard Shortcuts', self.config_parser,
os.path.join(get_kd_data_dir(), 'settings',
'shortcuts.json'))
示例10: handle
def handle(self, *args, **options):
styles = list(get_all_styles())
path = os.path.join(settings.MEDIA_ROOT, "css", "highlighting", "%s.css")
for style in styles:
f = file(path % style, "w+")
f.write(HtmlFormatter(style=style).get_style_defs('.highlight'))
f.close()
print "generated stylesheets for %i pygments styles" % len(styles)
示例11: pref_style
def pref_style():
styles = list(get_all_styles())
print "Choose from one of the styles"
count=1
for i in styles:
print count,":",i
count+=1
k=input()
return styles[k-1]
示例12: register_options
def register_options(cls, register):
register('--code-style', choices=list(get_all_styles()), default='friendly',
help='Use this stylesheet for code highlights.')
register('--open', action='store_true',
help='Open the generated documents in a browser.')
register('--fragment', action='store_true',
help='Generate a fragment of html to embed in a page.')
register('--extension', action='append', default=['.md', '.markdown'],
help='Process files with these extensions (as well as the standard extensions).')
示例13: register_options
def register_options(cls, register):
register('--code-style', choices=list(get_all_styles()), default='friendly',
help='Use this stylesheet for code highlights.')
register('--open', action='store_true',
help='Open the generated documents in a browser.')
register('--fragment', action='store_true',
help='Generate a fragment of html to embed in a page.')
register('--ignore-failure', default=False, action='store_true',
help='Do not consider rendering errors to be build errors.')
示例14: configure_codehighlight_options
def configure_codehighlight_options(option_group, mkflag):
all_styles = list(get_all_styles())
option_group.add_option(
mkflag("code-style"),
dest="markdown_to_html_code_style",
type="choice",
choices=all_styles,
help="Selects the stylesheet to use for code highlights, one of: " "%s." % " ".join(all_styles),
)
示例15: pygments_css
def pygments_css(schema='colorful'):
if schema=='list':
from pygments.styles import get_all_styles
_message_ok('Avalible styles: {}'.format(', '.join(list(get_all_styles()))))
else:
local("pygmentize -f html -S {schema} -a .codehilite > {static_root}/css/pygments.css".format(
static_root=django_settings.STATIC_ROOT,
schema=schema,
))