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


Python html.HtmlFormatter方法代码示例

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


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

示例1: html

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def html(self):
        """
        Return an HTML representation of the snippet.
        """
        formatter = HtmlFormatter(
            cssclass=self.DIV_CSS_CLASS,
            linenos=True,
            linenostart=self._start_line,
            hl_lines=self._shift_lines(
                self._violation_lines,
                self._start_line
            ),
            lineanchors=self._src_filename
        )

        return pygments.format(self.src_tokens(), formatter) 
开发者ID:Bachmann1234,项目名称:diff_cover,代码行数:18,代码来源:snippets.py

示例2: block_code

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def block_code(self, code, lang=None):
        """Rendering block level code. ``pre > code``.

        :param code: text content of the code block.
        :param lang: language of the given code.
        """
        code = code.rstrip('\n')  # 去掉尾部的换行符
        # 如果没有lang, 就返回代码块
        if not lang:
            code = mistune.escape(code)
            return '<pre><code>%s\n</code></pre>\n' % code

        # 给代码加上高亮  例如: lang='python'的话
        # ```python
        #   print('666')
        # ```
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ClassNotFound:
            # 如果lang是不合法, 没有匹配到, 就设置为python
            lexer = get_lexer_by_name('python', stripall=True)
        formatter = html.HtmlFormatter()  # linenos=True
        return highlight(code, lexer, formatter) 
开发者ID:enjoy-binbin,项目名称:Django-blog,代码行数:25,代码来源:mistune_markdown.py

示例3: __init__

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def __init__(self, parent, lexer=None):
        super(MyHighlighter, self).__init__(parent)

        self._document = self.document()
        self._formatter = HtmlFormatter(nowrap=True)
        self._lexer = lexer
        self.set_style('paraiso-dark') 
开发者ID:amimo,项目名称:dcc,代码行数:9,代码来源:sourcewindow.py

示例4: render_fenced_code

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def render_fenced_code(self, element):
        code = element.children[0].children
        options = CodeHiliteRendererMixin.options.copy()
        options.update(_parse_extras(getattr(element, "extra", None)))
        if element.lang:
            try:
                lexer = get_lexer_by_name(element.lang, stripall=True)
            except ClassNotFound:
                lexer = guess_lexer(code)
        else:
            lexer = guess_lexer(code)
        formatter = html.HtmlFormatter(**options)
        return highlight(code, lexer, formatter) 
开发者ID:frostming,项目名称:marko,代码行数:15,代码来源:codehilite.py

示例5: __init__

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def __init__(self, parent, lexer=None):
        super(PygmentsHighlighter, self).__init__(parent)

        self._document = self.document()
        self._formatter = HtmlFormatter(nowrap=True)
        self._lexer = lexer if lexer else PythonLexer()
        self.set_style('default') 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:pygments_highlighter.py

示例6: style_defs

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [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:Bachmann1234,项目名称:diff_cover,代码行数:10,代码来源:snippets.py

示例7: __init__

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def __init__(self, parent, lexer=None):
        super(PygmentsHighlighter, self).__init__(parent)

        self._document = self.document()
        self._formatter = HtmlFormatter(nowrap=True)
        self.set_style('default')
        if lexer is not None:
            self._lexer = lexer
        else:
            if PY3:
                self._lexer = Python3Lexer()
            else:
                self._lexer = PythonLexer() 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:15,代码来源:pygments_highlighter.py

示例8: handle_cli_output

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def handle_cli_output(self, cli_process: QProcess):
        output: QByteArray = cli_process.readAllStandardOutput()
        message = output.data().decode('utf-8').strip()

        if message.startswith('{') or message.startswith('['):
            formatter = HtmlFormatter()
            formatter.noclasses = True
            formatter.linenos = False
            formatter.nobackground = True
            message = highlight(message, JsonLexer(), formatter)
            self.output_area.insertHtml(message)
        else:
            self.output_area.append(message) 
开发者ID:lightning-power-users,项目名称:node-launcher,代码行数:15,代码来源:console.py

示例9: block_code

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def block_code(self, code, lang):
        if not lang:
            return '\n<pre><code>%s</code></pre>\n' % \
                mistune.escape(code)
        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = html.HtmlFormatter(noclasses=True)
        return highlight(code, lexer, formatter) 
开发者ID:naspeh,项目名称:mailur,代码行数:9,代码来源:html.py

示例10: __init__

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def __init__(self, document, lexer=None, color_scheme=None):
        super(PygmentsSH, self).__init__(document, color_scheme=color_scheme)
        self._pygments_style = self.color_scheme.name
        self._style = None
        self._formatter = HtmlFormatter(nowrap=True)
        self._lexer = lexer if lexer else PythonLexer()

        self._brushes = {}
        self._formats = {}
        self._init_style()
        self._prev_block = None 
开发者ID:TuringApp,项目名称:Turing,代码行数:13,代码来源:pygments_sh.py

示例11: block_code

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def block_code(code, lang=None):
        if not lang:
            return "\n<pre><code>%s</code></pre>\n" % mistune.escape(code)
        lexer = lexers.get_lexer_by_name(lang, stripall=True)
        formatter = html.HtmlFormatter()
        return pygments.highlight(code, lexer, formatter) 
开发者ID:chris104957,项目名称:maildown,代码行数:8,代码来源:renderer.py

示例12: blockcode

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def blockcode(self, text, lang):
        if not lang:
            return '\n<pre><code>{}</code></pre>\n'.format(houdini.escape_html(text.strip()))

        lexer = get_lexer_by_name(lang)
        formatter = HtmlFormatter()
        return highlight(text, lexer, formatter) 
开发者ID:richardchien-archive,项目名称:blog-a,代码行数:9,代码来源:util.py

示例13: save

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def save(self, *args, **kwargs):
        """
        Use the `pygments` library to create a highlighted HTML
        representation of the code snippet.
        """
        lexer = get_lexer_by_name(self.language)
        linenos = self.linenos and 'table' or False
        options = self.title and {'title': self.title} or {}
        formatter = HtmlFormatter(style=self.style, linenos=linenos,
                                  full=True, **options)
        self.highlighted = highlight(self.code, lexer, formatter)
        super(Snippet, self).save(*args, **kwargs) 
开发者ID:GetBlimp,项目名称:django-websocket-request-example,代码行数:14,代码来源:models.py

示例14: transform_code_to_html

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def transform_code_to_html(code, lang):
  if not lang:
    lang = "text"
  return highlight(code, get_lexer_by_name(dict(LANG_REGULAR_NAME).get(lang, lang)), HtmlFormatter()) 
开发者ID:F0RE1GNERS,项目名称:eoj3,代码行数:6,代码来源:language.py

示例15: make_report

# 需要导入模块: from pygments.formatters import html [as 别名]
# 或者: from pygments.formatters.html import HtmlFormatter [as 别名]
def make_report(self):
        """ Makes a html report and saves it into the same folder where logs are stored.
        """
        if self.eoexecutor.execution_stats is None:
            raise RuntimeError('Cannot produce a report without running the executor first, check EOExecutor.run '
                               'method')

        if os.environ.get('DISPLAY', '') == '':
            plt.switch_backend('Agg')

        try:
            dependency_graph = self._create_dependency_graph()
        except graphviz.backend.ExecutableNotFound as ex:
            dependency_graph = None
            warnings.warn("{}.\nPlease install the system package 'graphviz' (in addition "
                          "to the python package) to have the dependency graph in the final report!".format(ex),
                          Warning, stacklevel=2)

        formatter = HtmlFormatter(linenos=True)

        template = self._get_template()

        html = template.render(dependency_graph=dependency_graph,
                               general_stats=self.eoexecutor.general_stats,
                               task_descriptions=self._get_task_descriptions(),
                               task_sources=self._render_task_sources(formatter),
                               execution_stats=self._render_execution_errors(formatter),
                               execution_logs=self.eoexecutor.execution_logs,
                               execution_names=self.eoexecutor.execution_names,
                               code_css=formatter.get_style_defs())

        if not os.path.isdir(self.eoexecutor.report_folder):
            os.mkdir(self.eoexecutor.report_folder)

        with open(self.eoexecutor.get_report_filename(), 'w') as fout:
            fout.write(html) 
开发者ID:sentinel-hub,项目名称:eo-learn,代码行数:38,代码来源:eoexecutor_visualization.py


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