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


Python HtmlFormatter.format方法代码示例

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


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

示例1: test_valid_output

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
    def test_valid_output(self):
        # test all available wrappers
        fmt = HtmlFormatter(full=True, linenos=True, noclasses=True,
                            outencoding='utf-8')

        handle, pathname = tempfile.mkstemp('.html')
        tfile = os.fdopen(handle, 'w+b')
        fmt.format(tokensource, tfile)
        tfile.close()
        catname = os.path.join(TESTDIR, 'dtds', 'HTML4.soc')
        try:
            import subprocess
            po = subprocess.Popen(['nsgmls', '-s', '-c', catname, pathname],
                                  stdout=subprocess.PIPE)
            ret = po.wait()
            output = po.stdout.read()
            po.stdout.close()
        except OSError:
            # nsgmls not available
            pass
        else:
            if ret:
                print(output)
            self.assertFalse(ret, 'nsgmls run reported errors')

        os.unlink(pathname)
开发者ID:sol,项目名称:pygments,代码行数:28,代码来源:test_html_formatter.py

示例2: test_valid_output

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
    def test_valid_output(self):
        # test all available wrappers
        fmt = HtmlFormatter(full=True, linenos=True, noclasses=True,
                            outencoding='utf-8')

        handle, pathname = tempfile.mkstemp('.html')
        tfile = os.fdopen(handle, 'w+b')
        fmt.format(tokensource, tfile)
        tfile.close()
        catname = os.path.join(TESTDIR, 'dtds', 'HTML4.soc')
        try:
            try:
                import subprocess
                ret = subprocess.Popen(['nsgmls', '-s', '-c', catname, pathname],
                                       stdout=subprocess.PIPE).wait()
            except ImportError:
                # Python 2.3 - no subprocess module
                ret = os.popen('nsgmls -s -c "%s" "%s"' % (catname, pathname)).close()
                if ret == 32512: raise OSError  # not found
        except OSError:
            # nsgmls not available
            pass
        else:
            self.failIf(ret, 'nsgmls run reported errors')

        os.unlink(pathname)
开发者ID:erickt,项目名称:pygments,代码行数:28,代码来源:test_html_formatter.py

示例3: test_linenos

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def test_linenos(self):
     optdict = dict(linenos=True)
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre>\s+1\s+2\s+3", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例4: test_filename

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def test_filename(self):
     optdict = dict(filename="test.py")
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<span class=\"filename\">test.py</span><pre>", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例5: test_lineanchors_with_startnum

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def test_lineanchors_with_startnum(self):
     optdict = dict(lineanchors="foo", linenostart=5)
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre><span></span><a name=\"foo-5\">", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例6: test_linenos_with_startnum

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def test_linenos_with_startnum(self):
     optdict = dict(linenos=True, linenostart=5)
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre>\s+5\s+6\s+7", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例7: test_lineanchors

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def test_lineanchors(self):
     optdict = dict(lineanchors="foo")
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre><a name=\"foo-1\">", html))
开发者ID:hacksterio,项目名称:pygments.rb,代码行数:9,代码来源:test_html_formatter.py

示例8: test_all_options

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
    def test_all_options(self):
        for optdict in [dict(nowrap=True),
                        dict(linenos=True),
                        dict(linenos=True, full=True),
                        dict(linenos=True, full=True, noclasses=True)]:

            outfile = StringIO.StringIO()
            fmt = HtmlFormatter(**optdict)
            fmt.format(tokensource, outfile)
开发者ID:erickt,项目名称:pygments,代码行数:11,代码来源:test_html_formatter.py

示例9: test_unicode_options

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def test_unicode_options(self):
     fmt = HtmlFormatter(title=u'Föö',
                         cssclass=u'bär',
                         cssstyles=u'div:before { content: \'bäz\' }',
                         encoding='utf-8')
     handle, pathname = tempfile.mkstemp('.html')
     tfile = os.fdopen(handle, 'w+b')
     fmt.format(tokensource, tfile)
     tfile.close()
开发者ID:erickt,项目名称:pygments,代码行数:11,代码来源:test_html_formatter.py

示例10: test_correct_output

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
    def test_correct_output(self):
        hfmt = HtmlFormatter(nowrap=True)
        houtfile = StringIO.StringIO()
        hfmt.format(tokensource, houtfile)

        nfmt = NullFormatter()
        noutfile = StringIO.StringIO()
        nfmt.format(tokensource, noutfile)

        stripped_html = re.sub('<.*?>', '', houtfile.getvalue())
        escaped_text = escape_html(noutfile.getvalue())
        self.assertEquals(stripped_html, escaped_text)
开发者ID:erickt,项目名称:pygments,代码行数:14,代码来源:test_html_formatter.py

示例11: test_ctags

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def test_ctags(self):
     try:
         import ctags
     except ImportError:
         # we can't check without the ctags module, but at least check the exception
         self.assertRaises(RuntimeError, HtmlFormatter, tagsfile='support/tags')
     else:
         # this tagfile says that test_ctags() is on line 165, even if it isn't
         # anymore in the actual source
         fmt = HtmlFormatter(tagsfile='support/tags', lineanchors='L',
                             tagurlformat='%(fname)s%(fext)s')
         outfile = StringIO()
         fmt.format(tokensource, outfile)
         self.assertTrue('<a href="test_html_formatter.py#L-165">test_ctags</a>'
                         in outfile.getvalue())
开发者ID:sol,项目名称:pygments,代码行数:17,代码来源:test_html_formatter.py

示例12: test_external_css

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
    def test_external_css(self):
        # test correct behavior
        # CSS should be in /tmp directory
        fmt1 = HtmlFormatter(full=True, cssfile='fmt1.css')
        # CSS should be in testdir (testdir is absolute)
        fmt2 = HtmlFormatter(full=True, cssfile=join(testdir, 'fmt2.css'))
        tfile = tempfile.NamedTemporaryFile(suffix='.html')
        fmt1.format(tokensource, tfile)
        try:
            fmt2.format(tokensource, tfile)
            self.assert_(isfile(join(testdir, 'fmt2.css')))
        except IOError:
            # test directory not writable
            pass
        tfile.close()

        self.assert_(isfile(join(dirname(tfile.name), 'fmt1.css')))
        os.unlink(join(dirname(tfile.name), 'fmt1.css'))
        try:
            os.unlink(join(testdir, 'fmt2.css'))
        except OSError:
            pass
开发者ID:alon,项目名称:polinax,代码行数:24,代码来源:test_html_formatter.py

示例13: check

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import format [as 别名]
 def check(optdict):
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
开发者ID:sol,项目名称:pygments,代码行数:6,代码来源:test_html_formatter.py


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