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


Python HtmlFormatter.get_style_defs方法代码示例

本文整理汇总了Python中pygments.formatters.html.HtmlFormatter.get_style_defs方法的典型用法代码示例。如果您正苦于以下问题:Python HtmlFormatter.get_style_defs方法的具体用法?Python HtmlFormatter.get_style_defs怎么用?Python HtmlFormatter.get_style_defs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.formatters.html.HtmlFormatter的用法示例。


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

示例1: process_request

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
    def process_request(self, req):
        style = req.args['style']
        try:
            style_cls = get_style_by_name(style)
        except ValueError as e:
            raise HTTPNotFound(e)

        parts = style_cls.__module__.split('.')
        filename = resource_filename('.'.join(parts[:-1]), parts[-1] + '.py')
        mtime = datetime.fromtimestamp(os.path.getmtime(filename), localtz)
        last_modified = http_date(mtime)
        if last_modified == req.get_header('If-Modified-Since'):
            req.send_response(304)
            req.end_headers()
            return

        formatter = HtmlFormatter(style=style_cls)
        content = u'\n\n'.join([
            formatter.get_style_defs('div.code pre'),
            formatter.get_style_defs('table.code td')
        ]).encode('utf-8')

        req.send_response(200)
        req.send_header('Content-Type', 'text/css; charset=utf-8')
        req.send_header('Last-Modified', last_modified)
        req.send_header('Content-Length', len(content))
        req.write(content)
开发者ID:pkdevbox,项目名称:trac,代码行数:29,代码来源:pygments.py

示例2: _bbcodeAsHtml

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
 def _bbcodeAsHtml(self):
     style = get_style_by_name('igor')
     formatter = HtmlFormatter(style=style)
     lexer = get_lexer_by_name("bbcode", stripall=True)
     css = formatter.get_style_defs()
     txt = highlight(self._bbcode, lexer, HtmlFormatter())
     return "<style>%s</style>\n%s" % (css, txt)
开发者ID:ADFD,项目名称:adfd,代码行数:9,代码来源:model.py

示例3: prev_view_code

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
 def prev_view_code(self, code, laugange):
     htmlFormatter = HtmlFormatter()
     lexer = CppLexer()
     if laugange == "Cpp":
         lexer = CppLexer()
     elif laugange == "CSharp":
         lexer = CSharpLexer()
     codeDiv = highlight(code, lexer, htmlFormatter)
     codeCss = htmlFormatter.get_style_defs(".highlight")
     #
     html = """
     <html>
         <head>
             <style type="text/css">
             %s
             </style>
         </head>
         <body>
         %s
         </body>
     </html>
     """ % (codeCss, codeDiv)
     self.webView.setHtml(html)
     self.setStyleSheet(codeCss)
     # 输出文件测试验证
     # ff = open('test.html', 'w')
     # ff.write(html)
     # ff.close()
     pass
开发者ID:tylerzhu,项目名称:ExcelConvert,代码行数:31,代码来源:preViewClass.py

示例4: render_code

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
    def render_code(self):
        formatter = HtmlFormatter(style='default', nowrap=True, classprefix='code%s-' % self.pk)
        html = highlight(self.code, get_lexer_by_name(self.syntax), formatter)
        css = formatter.get_style_defs()

        # Included in a DIV, so the next item will be displayed below.
        return _('<div class="code"><style type="text/css">%(css)s</style>\n<pre>%(html)s</pre></div>\n') % {'css':css, 'html':html}
开发者ID:mrJayson,项目名称:lmsunsw,代码行数:9,代码来源:models.py

示例5: style_defs

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
 def style_defs(cls):
     """
     Return the CSS style definitions required
     by the formatted snippet.
     """
     formatter = HtmlFormatter()
     formatter.style.highlight_color = cls.VIOLATION_COLOR
     return formatter.get_style_defs()
开发者ID:Shoobx,项目名称:diff-cover,代码行数:10,代码来源:snippets.py

示例6: highlight_paste

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
def highlight_paste(paste, hl_lines):
    '''Use pygments to syntax highlight a paste, returns by the way the CSS'''
    lexer = get_lexer_by_name(paste.hl_alias)
    formatter = HtmlFormatter(linenos=True, cssclass='source', hl_lines=hl_lines)
    return (
        highlight(paste.content, lexer, formatter),
        formatter.get_style_defs('.source')
    )
开发者ID:GabrielC101,项目名称:PPaste,代码行数:10,代码来源:main.py

示例7: process_request

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
    def process_request(self, req):
        # settings panel
        if not 'style' in req.args:
            req._no_pygments_stylesheet = True
            styles = list(get_all_styles())
            styles.sort(lambda a, b: cmp(a.lower(), b.lower()))

            if req.method == 'POST':
                style = req.args.get('new_style')
                if style and style in styles:
                    req.session['pygments_style'] = style

            output = self._highlight('html', self.EXAMPLE, False)
            req.hdf['output'] = Markup(output)
            req.hdf['current'] = req.session.get('pygments_style',
                                                 self.default_style)
            req.hdf['styles'] = styles
            req.hdf['pygments_path'] = self.env.href.pygments()
            return 'pygments_settings.cs', None

        # provide stylesheet
        else:
            style = req.args['style']

            parts = style.__module__.split('.')
            filename = resource_filename('.'.join(parts[:-1]), parts[-1] + '.py')
            mtime = datetime.utcfromtimestamp(os.path.getmtime(filename))
            last_modified = http_date(time.mktime(mtime.timetuple()))
            if last_modified == req.get_header('If-Modified-Since'):
                req.send_response(304)
                req.end_headers()
                return

            formatter = HtmlFormatter(style=style)
            content = u'\n\n'.join([
                formatter.get_style_defs('div.code pre'),
                formatter.get_style_defs('table.code td')
            ]).encode('utf-8')

            req.send_response(200)
            req.send_header('Content-Type', 'text/css; charset=utf-8')
            req.send_header('Last-Modified', last_modified)
            req.send_header('Content-Length', len(content))
            req.write(content)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:46,代码来源:__init__.py

示例8: get

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
 def get(self, paste_id):
     try:
         aid = b64.num_decode(paste_id)
         paste = Paste.get_by_id(aid)
         content, lang = paste.content, paste.type
         formatter = HtmlFormatter()
         self.response.out.write(template.render("paste.html", {'css': formatter.get_style_defs('.highlight'),
                                                                'paste': highlight(content, get_lexer_by_name(lang), formatter)}))
     except Exception:
         self.response.set_status(404)
         self.response.out.write(template.render("404.html", {}))
开发者ID:itsbth,项目名称:My-First-Pastebin,代码行数:13,代码来源:pastebin.py

示例9: render_code

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
def render_code(instance, style_name='default'):
    # Some interesting options in the HtmlFormatter:
    # - nowrap       -> no wrap inside <pre>
    # - classprefix  -> prefix for the classnames
    # - noclasses    -> all inline styles.
    #
    # To get_style_defs(), you can pass a selector prefix.
    #
    style = styles.get_style_by_name(style_name)
    formatter = HtmlFormatter(linenos=instance.linenumbers, style=style, nowrap=True, classprefix='code%s-' % instance.pk)
    html = highlight(instance.code, get_lexer_by_name(instance.language), formatter)
    css = formatter.get_style_defs()

    # Included in a DIV, so the next item will be displayed below.
    return '<div class="code"><style type="text/css">' + css + '</style>\n<pre>' + html + '</pre></div>\n'
开发者ID:django-fluent,项目名称:django-fluent-contents,代码行数:17,代码来源:backend.py

示例10: export

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
def export():
    if not os.path.exists(PYGMENTS_PATH):
        os.makedirs(PYGMENTS_PATH)

    styles = list(get_all_styles())

    for style in styles:
        print("Generating CSS for %s" % style)

        opts = {"style": style}

        path = os.path.join(PYGMENTS_PATH, "%s.css" % style)
        formatter = HtmlFormatter(**opts)
        css_content = formatter.get_style_defs()
        # little fix because pelican doesn't append background color.
        css_content = css_content.replace(".hll", ".highlight")

        with open(path, "w") as f:
            f.write(css_content)
开发者ID:aroaminggeek,项目名称:Flex,代码行数:21,代码来源:generate.py

示例11: export

# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import get_style_defs [as 别名]
def export():
    if not os.path.exists(PYGMENTS_PATH):
        os.makedirs(PYGMENTS_PATH)

    styles = list(get_all_styles())

    for style in styles:
        print('Generating CSS for %s' % style)

        opts = {
            'style': style,
            'noclasses': False,
            'nobackground': False,
        }

        path = os.path.join(PYGMENTS_PATH, '%s.css' % style)
        formatter = HtmlFormatter(**opts)
        css_content = formatter.get_style_defs('.highlight')

        with open(path, 'w') as f:
            f.write(css_content)
开发者ID:nrjones8,项目名称:blog,代码行数:23,代码来源:generate.py


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