当前位置: 首页>>代码示例>>Python>>正文


Python formatters.get_formatter_by_name函数代码示例

本文整理汇总了Python中pygments.formatters.get_formatter_by_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_formatter_by_name函数的具体用法?Python get_formatter_by_name怎么用?Python get_formatter_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_formatter_by_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: serve_language_css

def serve_language_css(style):
    try:
        fmt = formatters.get_formatter_by_name('html', style=style)
    except:
        util.log.warn(
            'Style "%s" cannot be found, falling back to default' % (style,)
        )
        fmt = formatters.get_formatter_by_name('html')
    bottle.response.content_type = 'text/css'
    return fmt.get_style_defs(['.pygmentized'])
开发者ID:AWinterman,项目名称:pasttle,代码行数:10,代码来源:server.py

示例2: get_pygment_style

def get_pygment_style(style, css_class='codehilite'):
    """Get the specified pygments sytle CSS."""

    try:
        # Try and request pygments to generate it
        text = get_formatter_by_name('html', style=style).get_style_defs('.' + css_class)
    except Exception:
        # Try and request pygments to generate default
        text = get_formatter_by_name('html', style="default").get_style_defs('.' + css_class)
    return '<style>\n%s\n</style>\n' % text if text is not None else ""
开发者ID:filltr,项目名称:PyMdown,代码行数:10,代码来源:__init__.py

示例3: get_context

    def get_context(self, value, parent_context=None):
        context = super().get_context(value, parent_context=parent_context)
        src = value.get('code') or ''
        src = src.strip('\n')
        lang = value.get('language') or ''
        line_numbers = value['line_numbers']

        if lang:
            lexer = get_lexer_by_name(lang)
        else:
            lexer = guess_lexer(src)
        formatter = get_formatter_by_name(
            'html',
            linenos=line_numbers,
            cssclass='codehilite',
            style='default',
            noclasses=False,
        )
        context.update({
            'filename': value.get('filename'),
            'display_filename': value.get('display_filename'),
            'language': value.get('lang'),
            'code': mark_safe(highlight(src, lexer, formatter))
        })
        return context
开发者ID:jmichalicek,项目名称:bash-shell.net,代码行数:25,代码来源:code_block.py

示例4: hljsx

def hljsx(code):
    lexer = get_lexer_by_name('jsx')
    formatter = get_formatter_by_name('html')
    hl = highlight(code, lexer, formatter)
    if isinstance(hl, str):
        return hl
    return hl.encode('utf-8')
开发者ID:richardbann,项目名称:pygments-lexer-babylon,代码行数:7,代码来源:test_project.py

示例5: get_printer

def get_printer(mode='auto'):
    """
    Generate printer function.

    :param mode: string: always, never or auto
    :return:
    """

    def printer(data):
        print(data)

    if mode in ('auto', 'always'):
        try:
            from pygments import highlight
            from pygments.lexers import get_lexer_by_name
            from pygments.formatters import get_formatter_by_name

            if mode == 'always' or sys.stdout.isatty():
                lexer = get_lexer_by_name('json')
                formatter = get_formatter_by_name('terminal256')

                def printer(data):
                    print(highlight(data, lexer, formatter), end='', file=sys.stdout)
        except ImportError as e:
            if mode == 'always':
                import warnings
                warnings.warn('No pygments module available, cannot colorize output')

    return printer
开发者ID:msztolcman,项目名称:jsontool,代码行数:29,代码来源:jsontool.py

示例6: create_code_css

 def create_code_css():
     from pygments.formatters import get_formatter_by_name
     formatter = get_formatter_by_name('html', style=kw["code_color_scheme"])
     utils.makedirs(os.path.dirname(code_css_path))
     with codecs.open(code_css_path, 'wb+', 'utf8') as outf:
         outf.write(formatter.get_style_defs(kw["code.css_selectors"]))
         outf.write(kw["code.css_close"])
开发者ID:osama-afifi,项目名称:nikola,代码行数:7,代码来源:copy_assets.py

示例7: diff_revs

def diff_revs(wiki, user, rev, raw=False):
    diff = wiki.scm.diff(path=None, rev1=rev, rev2=None)
    if not raw:
        lexer = get_lexer_by_name('diff')
        formatter = get_formatter_by_name('html')
        diff = highlight(diff, lexer, formatter)
    return {'diff': diff, 'disp_rev': rev}
开发者ID:ludovicchabant,项目名称:Wikked,代码行数:7,代码来源:history.py

示例8: process_request

def process_request(json_data):
    log.debug('Processing: path: %s\n%s:%s' % (json_data['fullPath'], json_data['action'], json_data['language']))

    try:
      code = json_data['code']

      fmter = get_formatter_by_name(json_data['outformat'], linenos = json_data['linenos'], lineanchors = json_data['lineanchors'])
      fmter.encoding = json_data['encoding'] 

      lexer = get_lexer_by_name(json_data['language'])

      return highlight(code, lexer, fmter)
    except ValueError as err:
      log.error(err)
      return ''' 
        <h1><a href="http://pygments.org">Pygments</a> failed to highlight this file</h1>
        <div>You should consider filing a bug report or provide a bug fix to help the community ;)</div>
        <div>
          The Error was:
            <pre>%s</pre>
        </div>
        <div>
          The code that was parsed is:
            <pre>%s</pre>
        </div>
        ''' % (err, code)
开发者ID:thlorenz,项目名称:readarepo-zip,代码行数:26,代码来源:pygments-service.py

示例9: create_code_css

 def create_code_css():
     from pygments.formatters import get_formatter_by_name
     formatter = get_formatter_by_name('html', style=kw["code_color_scheme"])
     utils.makedirs(os.path.dirname(code_css_path))
     with codecs.open(code_css_path, 'wb+', 'utf8') as outf:
         outf.write(formatter.get_style_defs('pre.code'))
         outf.write("table.codetable { width: 100%;} td.linenos {text-align: right; width: 4em;}")
开发者ID:Liessae,项目名称:nikola,代码行数:7,代码来源:copy_assets.py

示例10: format

 def format(self, code, language):
    if language == "":
       lexer = guess_lexer(code)
    else:
       lexer = get_lexer_by_name(language)
    formatter = get_formatter_by_name(self.formatname)
    return highlight(code, lexer, formatter)
开发者ID:Aladdinn,项目名称:xslt20-stylesheets,代码行数:7,代码来源:DocBookPygmenter.py

示例11: render

    def render(self, value):
        src = value["code"].strip("\n")
        lang = value["language"]

        lexer = get_lexer_by_name(lang)
        formatter = get_formatter_by_name("html", linenos=None, cssclass="codehilite", style="default", noclasses=False)
        return mark_safe(highlight(src, lexer, formatter))
开发者ID:tobiase,项目名称:wagtail-components,代码行数:7,代码来源:code_highlight.py

示例12: ConvertCodeToHtml

 def ConvertCodeToHtml(self, code):
     from pygments import highlight
     from pygments.lexers import get_lexer_by_name
     from pygments.formatters import get_formatter_by_name
     lexer = get_lexer_by_name('python')
     formatter = get_formatter_by_name('html', noclasses=True)
     return highlight(code, lexer, formatter)
开发者ID:jmt4b04d4v,项目名称:ConfluenceWikiAndRST,代码行数:7,代码来源:pydev_wiki_to_rst.py

示例13: highlight

def highlight(context, body, syntax, format='html'):
    """Looks up the appropriate Pygments lexer for a given syntax
    and uses it to format the passed body.
    """
    lexer = get_lexer_by_name(syntax)
    formatter = get_formatter_by_name(format)
    
    return pygments.highlight(body, lexer, formatter)
开发者ID:Letractively,项目名称:python-redfox.redpaste,代码行数:8,代码来源:highlight.py

示例14: pygments_style

def pygments_style(style):
    try:
        string = get_formatter_by_name('html', style=style).get_style_defs('.highlight')
    except ClassNotFound:
        logger.warning('Unknown Pygments style %s', style)
        string = '/* nothing */'

    return string
开发者ID:trompette,项目名称:blog,代码行数:8,代码来源:templating.py

示例15: traceback_code

 def traceback_code(self, task):
     formatter = get_formatter_by_name('html')
     if sys.version_info.major == 3:
         lexer = get_lexer_by_name('py3tb')
     else:
         lexer = get_lexer_by_name('pytb')
     style = formatter.get_style_defs('.highlight')
     return mark_safe('<style>{}</style><br/>{}'.format(style, highlight(task.traceback, lexer, formatter)))
开发者ID:barbuza,项目名称:django-robust,代码行数:8,代码来源:admin.py


注:本文中的pygments.formatters.get_formatter_by_name函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。