當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。