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


Python highlighting.PygmentsBridge类代码示例

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


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

示例1: test_trim_doctest_flags

def test_trim_doctest_flags():
    PygmentsBridge.html_formatter = MyFormatter
    try:
        bridge = PygmentsBridge("html", trim_doctest_flags=True)
        ret = bridge.highlight_block(">>> 1+2 # doctest: SKIP\n3\n", "pycon")
        assert ret == ">>> 1+2 \n3\n"
    finally:
        PygmentsBridge.html_formatter = HtmlFormatter
开发者ID:Lyoness,项目名称:sphinx,代码行数:8,代码来源:test_highlighting.py

示例2: test_set_formatter

def test_set_formatter():
    PygmentsBridge.html_formatter = MyFormatter
    try:
        bridge = PygmentsBridge('html')
        ret = bridge.highlight_block('foo\n', 'python')
        assert ret == 'foo\n'
    finally:
        PygmentsBridge.html_formatter = HtmlFormatter
开发者ID:APSL,项目名称:django-braces,代码行数:8,代码来源:test_highlighting.py

示例3: __init__

 def __init__(self, builder, *args, **kwds):
     BaseTranslator.__init__(self, *args, **kwds)
     self.highlighter = PygmentsBridge('html', builder.config.pygments_style)
     self.no_smarty = 0
     self.builder = builder
     self.highlightlang = 'python'
     self.highlightlinenothreshold = sys.maxint
开发者ID:lshmenor,项目名称:IMTAphy,代码行数:7,代码来源:htmlwriter.py

示例4: __init__

 def __init__(self, builder, *args, **kwds):
     BaseTranslator.__init__(self, *args, **kwds)
     self.highlighter = PygmentsBridge('html', builder.config.pygments_style)
     self.no_smarty = 0
     self.builder = builder
     self.highlightlang = builder.config.highlight_language
     self.highlightlinenothreshold = sys.maxint
     self.protect_literal_text = 0
开发者ID:BackupGGCode,项目名称:sphinx,代码行数:8,代码来源:htmlwriter.py

示例5: init_highlighter

 def init_highlighter(self):
     # determine Pygments style and create the highlighter
     if self.config.pygments_style is not None:
         style = self.config.pygments_style
     elif self.theme:
         style = self.theme.get_confstr('theme', 'pygments_style', 'none')
     else:
         style = 'sphinx'
     self.highlighter = PygmentsBridge('html', style,
                                       self.config.trim_doctest_flags)
开发者ID:Titan-C,项目名称:sphinx,代码行数:10,代码来源:html.py

示例6: test_default_highlight

def test_default_highlight(logger):
    bridge = PygmentsBridge('html')

    # default: highlights as python3
    ret = bridge.highlight_block('print "Hello sphinx world"', 'default')
    assert ret == ('<div class="highlight"><pre><span></span><span class="nb">print</span> '
                   '<span class="s2">&quot;Hello sphinx world&quot;</span>\n</pre></div>\n')

    # default: fallbacks to none if highlighting failed
    ret = bridge.highlight_block('reST ``like`` text', 'default')
    assert ret == '<div class="highlight"><pre><span></span>reST ``like`` text\n</pre></div>\n'

    # python3: highlights as python3
    ret = bridge.highlight_block('print "Hello sphinx world"', 'python3')
    assert ret == ('<div class="highlight"><pre><span></span><span class="nb">print</span> '
                   '<span class="s2">&quot;Hello sphinx world&quot;</span>\n</pre></div>\n')

    # python3: raises error if highlighting failed
    ret = bridge.highlight_block('reST ``like`` text', 'python3')
    logger.warning.assert_called_with('Could not lex literal_block as "%s". '
                                      'Highlighting skipped.', 'python3',
                                      type='misc', subtype='highlighting_failure',
                                      location=None)
开发者ID:AWhetter,项目名称:sphinx,代码行数:23,代码来源:test_highlighting.py

示例7: test_default_highlight

def test_default_highlight():
    bridge = PygmentsBridge('html')

    # default: highlights as python3
    ret = bridge.highlight_block('print "Hello sphinx world"', 'default')
    assert ret == ('<div class="highlight"><pre><span></span><span class="nb">print</span> '
                   '<span class="s2">&quot;Hello sphinx world&quot;</span>\n</pre></div>\n')

    # default: fallbacks to none if highlighting failed
    ret = bridge.highlight_block('reST ``like`` text', 'default')
    assert ret == '<div class="highlight"><pre><span></span>reST ``like`` text\n</pre></div>\n'

    # python3: highlights as python3
    ret = bridge.highlight_block('print "Hello sphinx world"', 'python3')
    assert ret == ('<div class="highlight"><pre><span></span><span class="nb">print</span> '
                   '<span class="s2">&quot;Hello sphinx world&quot;</span>\n</pre></div>\n')

    # python3: raises error if highlighting failed
    try:
        ret = bridge.highlight_block('reST ``like`` text', 'python3')
        assert False, "highlight_block() does not raise any exceptions"
    except ErrorToken:
        pass  # raise parsing error
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:23,代码来源:test_highlighting.py

示例8: test_add_lexer

def test_add_lexer(app):
    app.add_lexer('test', MyLexer())

    bridge = PygmentsBridge('html')
    ret = bridge.highlight_block('ab', 'test')
    assert '<span class="n">a</span>b' in ret
开发者ID:APSL,项目名称:django-braces,代码行数:6,代码来源:test_highlighting.py

示例9: StandaloneHTMLBuilder

class StandaloneHTMLBuilder(Builder):
    """
    Builds standalone HTML docs.
    """
    name = 'html'
    format = 'html'
    copysource = True
    allow_parallel = True
    out_suffix = '.html'
    link_suffix = '.html'  # defaults to matching out_suffix
    indexer_format = js_index
    indexer_dumps_unicode = True
    supported_image_types = ['image/svg+xml', 'image/png',
                             'image/gif', 'image/jpeg']
    searchindex_filename = 'searchindex.js'
    add_permalinks = True
    embedded = False  # for things like HTML help or Qt help: suppresses sidebar
    search = True  # for things like HTML help and Apple help: suppress search

    # This is a class attribute because it is mutated by Sphinx.add_javascript.
    script_files = ['_static/jquery.js', '_static/underscore.js',
                    '_static/doctools.js']
    # Dito for this one.
    css_files = []

    default_sidebars = ['localtoc.html', 'relations.html',
                        'sourcelink.html', 'searchbox.html']

    # cached publisher object for snippets
    _publisher = None

    def init(self):
        # a hash of all config values that, if changed, cause a full rebuild
        self.config_hash = ''
        self.tags_hash = ''
        # basename of images directory
        self.imagedir = '_images'
        # section numbers for headings in the currently visited document
        self.secnumbers = {}
        # currently written docname
        self.current_docname = None

        self.init_templates()
        self.init_highlighter()
        self.init_translator_class()
        if self.config.html_file_suffix is not None:
            self.out_suffix = self.config.html_file_suffix

        if self.config.html_link_suffix is not None:
            self.link_suffix = self.config.html_link_suffix
        else:
            self.link_suffix = self.out_suffix

        if self.config.language is not None:
            if self._get_translations_js():
                self.script_files.append('_static/translations.js')

    def _get_translations_js(self):
        candidates = [path.join(package_dir, 'locale', self.config.language,
                                'LC_MESSAGES', 'sphinx.js'),
                      path.join(sys.prefix, 'share/sphinx/locale',
                                self.config.language, 'sphinx.js')] + \
                     [path.join(dir, self.config.language,
                                'LC_MESSAGES', 'sphinx.js')
                      for dir in self.config.locale_dirs]
        for jsfile in candidates:
            if path.isfile(jsfile):
                return jsfile
        return None

    def get_theme_config(self):
        return self.config.html_theme, self.config.html_theme_options

    def init_templates(self):
        Theme.init_themes(self.confdir, self.config.html_theme_path,
                          warn=self.warn)
        themename, themeoptions = self.get_theme_config()
        self.theme = Theme(themename, warn=self.warn)
        self.theme_options = themeoptions.copy()
        self.create_template_bridge()
        self.templates.init(self, self.theme)

    def init_highlighter(self):
        # determine Pygments style and create the highlighter
        if self.config.pygments_style is not None:
            style = self.config.pygments_style
        elif self.theme:
            style = self.theme.get_confstr('theme', 'pygments_style', 'none')
        else:
            style = 'sphinx'
        self.highlighter = PygmentsBridge('html', style,
                                          self.config.trim_doctest_flags)

    def init_translator_class(self):
        if self.translator_class is not None:
            pass
        elif self.config.html_translator_class:
            self.translator_class = self.app.import_object(
                self.config.html_translator_class,
                'html_translator_class setting')
#.........这里部分代码省略.........
开发者ID:Titan-C,项目名称:sphinx,代码行数:101,代码来源:html.py

示例10: test_lexer_options

def test_lexer_options():
    bridge = PygmentsBridge('html')
    ret = bridge.highlight_block('//comment', 'php', opts={'startinline': True})
    assert '<span class="c1">//comment</span>' in ret
开发者ID:AWhetter,项目名称:sphinx,代码行数:4,代码来源:test_highlighting.py

示例11: HTMLTranslator

class HTMLTranslator(BaseTranslator):
    """
    Our custom HTML translator.
    """

    def __init__(self, builder, *args, **kwds):
        BaseTranslator.__init__(self, *args, **kwds)
        self.highlighter = PygmentsBridge('html', builder.config.pygments_style)
        self.no_smarty = 0
        self.builder = builder
        self.highlightlang = 'python'
        self.highlightlinenothreshold = sys.maxint
        self.protect_literal_text = 0

    def visit_desc(self, node):
        self.body.append(self.starttag(node, 'dl', CLASS=node['desctype']))
    def depart_desc(self, node):
        self.body.append('</dl>\n\n')

    def visit_desc_signature(self, node):
        # the id is set automatically
        self.body.append(self.starttag(node, 'dt'))
        # anchor for per-desc interactive data
        if node.parent['desctype'] != 'describe' and node['ids'] and node['first']:
            self.body.append('<!--[%s]-->' % node['ids'][0])
        if node.parent['desctype'] in ('class', 'exception'):
            self.body.append('%s ' % node.parent['desctype'])
    def depart_desc_signature(self, node):
        if node['ids'] and self.builder.name != 'htmlhelp':
            self.body.append(u'<a class="headerlink" href="#%s" ' % node['ids'][0] +
                             u'title="Permalink to this definition">\u00B6</a>')
        self.body.append('</dt>\n')

    def visit_desc_addname(self, node):
        self.body.append(self.starttag(node, 'tt', '', CLASS='descclassname'))
    def depart_desc_addname(self, node):
        self.body.append('</tt>')

    def visit_desc_type(self, node):
        pass
    def depart_desc_type(self, node):
        pass

    def visit_desc_name(self, node):
        self.body.append(self.starttag(node, 'tt', '', CLASS='descname'))
    def depart_desc_name(self, node):
        self.body.append('</tt>')

    def visit_desc_parameterlist(self, node):
        self.body.append('<big>(</big>')
        self.first_param = 1
    def depart_desc_parameterlist(self, node):
        self.body.append('<big>)</big>')

    def visit_desc_parameter(self, node):
        if not self.first_param:
            self.body.append(', ')
        else:
            self.first_param = 0
        if not node.hasattr('noemph'):
            self.body.append('<em>')
    def depart_desc_parameter(self, node):
        if not node.hasattr('noemph'):
            self.body.append('</em>')

    def visit_desc_optional(self, node):
        self.body.append('<span class="optional">[</span>')
    def depart_desc_optional(self, node):
        self.body.append('<span class="optional">]</span>')

    def visit_desc_annotation(self, node):
        self.body.append(self.starttag(node, 'em', CLASS='property'))
    def depart_desc_annotation(self, node):
        self.body.append('</em>')

    def visit_desc_content(self, node):
        self.body.append(self.starttag(node, 'dd', ''))
    def depart_desc_content(self, node):
        self.body.append('</dd>')

    def visit_refcount(self, node):
        self.body.append(self.starttag(node, 'em', '', CLASS='refcount'))
    def depart_refcount(self, node):
        self.body.append('</em>')

    def visit_versionmodified(self, node):
        self.body.append(self.starttag(node, 'p'))
        text = version_text[node['type']] % node['version']
        if len(node):
            text += ': '
        else:
            text += '.'
        self.body.append('<span class="versionmodified">%s</span>' % text)
    def depart_versionmodified(self, node):
        self.body.append('</p>\n')

    # overwritten
    def visit_reference(self, node):
        BaseTranslator.visit_reference(self, node)
        if node.hasattr('reftitle'):
#.........这里部分代码省略.........
开发者ID:lshmenor,项目名称:IMTAphy,代码行数:101,代码来源:htmlwriter.py

示例12: __init__

 def __init__(self, dest='docx', stylename='sphinx',
               trim_doctest_flags=False):
  PygmentsBridge.__init__(self, dest, stylename, trim_doctest_flags)
  dest = "html"
  self.formatter = DocxFormatter
开发者ID:laboshinl,项目名称:openstack-grizzly-guide,代码行数:5,代码来源:highlight.py

示例13: test_add_lexer

def test_add_lexer(app, status, warning):
    app.add_lexer("test", MyLexer())

    bridge = PygmentsBridge("html")
    ret = bridge.highlight_block("ab", "test")
    assert '<span class="n">a</span>b' in ret
开发者ID:Lyoness,项目名称:sphinx,代码行数:6,代码来源:test_highlighting.py

示例14: HTMLTranslator

class HTMLTranslator(BaseTranslator):
    """
    Our custom HTML translator.
    """

    def __init__(self, builder, *args, **kwds):
        BaseTranslator.__init__(self, *args, **kwds)
        self.highlighter = PygmentsBridge('html', builder.config.pygments_style)
        self.no_smarty = 0
        self.builder = builder
        self.highlightlang = 'python'
        self.highlightlinenothreshold = sys.maxint
        self.language.labels['warning'] = 'Caveat'

    def visit_desc(self, node):
        self.body.append(self.starttag(node, 'dl', CLASS=node['desctype']))
    def depart_desc(self, node):
        self.body.append('</dl>\n\n')

    def visit_desc_signature(self, node):
        # the id is set automatically
        self.body.append(self.starttag(node, 'dt'))
        # anchor for per-desc interactive data
        if node.parent['desctype'] != 'describe' and node['ids'] and node['first']:
            self.body.append('<!--#%s#-->' % node['ids'][0])
        if node.parent['desctype'] in ('class', 'exception'):
            self.body.append('%s ' % node.parent['desctype'])
    def depart_desc_signature(self, node):
        if node['ids'] and self.builder.name != 'htmlhelp':
            self.body.append(u'<a class="headerlink" href="#%s" ' % node['ids'][0] +
                             u'title="Permalink to this definition">\u00B6</a>')
        self.body.append('</dt>\n')

    def visit_desc_classname(self, node):
        self.body.append(self.starttag(node, 'tt', '', CLASS='descclassname'))
    def depart_desc_classname(self, node):
        self.body.append('</tt>')

    def visit_desc_type(self, node):
        # return type of C functions -- nothing to do here
        pass
    def depart_desc_type(self, node):
        pass

    def visit_desc_name(self, node):
        self.body.append(self.starttag(node, 'tt', '', CLASS='descname'))
    def depart_desc_name(self, node):
        self.body.append('</tt>')

    def visit_desc_parameterlist(self, node):
        self.body.append('<big>(</big>')
        self.first_param = 1
    def depart_desc_parameterlist(self, node):
        self.body.append('<big>)</big>')

    def visit_desc_parameter(self, node):
        if not self.first_param:
            self.body.append(', ')
        else:
            self.first_param = 0
        if not node.hasattr('noemph'):
            self.body.append('<em>')
    def depart_desc_parameter(self, node):
        if not node.hasattr('noemph'):
            self.body.append('</em>')

    def visit_desc_optional(self, node):
        self.body.append('<span class="optional">[</span>')
    def depart_desc_optional(self, node):
        self.body.append('<span class="optional">]</span>')

    def visit_desc_content(self, node):
        self.body.append(self.starttag(node, 'dd', ''))
    def depart_desc_content(self, node):
        self.body.append('</dd>')

    def visit_refcount(self, node):
        self.body.append(self.starttag(node, 'em', '', CLASS='refcount'))
    def depart_refcount(self, node):
        self.body.append('</em>')

    def visit_versionmodified(self, node):
        self.body.append(self.starttag(node, 'p'))
        text = version_text[node['type']] % node['version']
        if len(node):
            text += ': '
        else:
            text += '.'
        self.body.append('<span class="versionmodified">%s</span>' % text)
    def depart_versionmodified(self, node):
        self.body.append('</p>\n')

    # overwritten
    def visit_reference(self, node):
        BaseTranslator.visit_reference(self, node)
        if node.hasattr('reftitle'):
            # ugly hack to add a title attribute
            starttag = self.body[-1]
            if not starttag.startswith('<a '):
                return
#.........这里部分代码省略.........
开发者ID:lshmenor,项目名称:IMTAphy,代码行数:101,代码来源:htmlwriter.py

示例15: HTMLTranslator

class HTMLTranslator(BaseTranslator):
    """
    Our custom HTML translator.
    """

    def __init__(self, builder, *args, **kwds):
        BaseTranslator.__init__(self, *args, **kwds)
        self.highlighter = PygmentsBridge("html", builder.config.pygments_style)
        self.no_smarty = 0
        self.builder = builder
        self.highlightlang = builder.config.highlight_language
        self.highlightlinenothreshold = sys.maxint
        self.protect_literal_text = 0

    def visit_desc(self, node):
        self.body.append(self.starttag(node, "dl", CLASS=node["desctype"]))

    def depart_desc(self, node):
        self.body.append("</dl>\n\n")

    def visit_desc_signature(self, node):
        # the id is set automatically
        self.body.append(self.starttag(node, "dt"))
        # anchor for per-desc interactive data
        if node.parent["desctype"] != "describe" and node["ids"] and node["first"]:
            self.body.append("<!--[%s]-->" % node["ids"][0])
        if node.parent["desctype"] in ("class", "exception"):
            self.body.append("%s " % node.parent["desctype"])

    def depart_desc_signature(self, node):
        if node["ids"] and self.builder.add_definition_links:
            self.body.append(
                u'<a class="headerlink" href="#%s" ' % node["ids"][0]
                + u'title="%s">\u00B6</a>' % _("Permalink to this definition")
            )
        self.body.append("</dt>\n")

    def visit_desc_addname(self, node):
        self.body.append(self.starttag(node, "tt", "", CLASS="descclassname"))

    def depart_desc_addname(self, node):
        self.body.append("</tt>")

    def visit_desc_type(self, node):
        pass

    def depart_desc_type(self, node):
        pass

    def visit_desc_name(self, node):
        self.body.append(self.starttag(node, "tt", "", CLASS="descname"))

    def depart_desc_name(self, node):
        self.body.append("</tt>")

    def visit_desc_parameterlist(self, node):
        self.body.append("<big>(</big>")
        self.first_param = 1

    def depart_desc_parameterlist(self, node):
        self.body.append("<big>)</big>")

    def visit_desc_parameter(self, node):
        if not self.first_param:
            self.body.append(", ")
        else:
            self.first_param = 0
        if not node.hasattr("noemph"):
            self.body.append("<em>")

    def depart_desc_parameter(self, node):
        if not node.hasattr("noemph"):
            self.body.append("</em>")

    def visit_desc_optional(self, node):
        self.body.append('<span class="optional">[</span>')

    def depart_desc_optional(self, node):
        self.body.append('<span class="optional">]</span>')

    def visit_desc_annotation(self, node):
        self.body.append(self.starttag(node, "em", CLASS="property"))

    def depart_desc_annotation(self, node):
        self.body.append("</em>")

    def visit_desc_content(self, node):
        self.body.append(self.starttag(node, "dd", ""))

    def depart_desc_content(self, node):
        self.body.append("</dd>")

    def visit_refcount(self, node):
        self.body.append(self.starttag(node, "em", "", CLASS="refcount"))

    def depart_refcount(self, node):
        self.body.append("</em>")

    def visit_versionmodified(self, node):
        self.body.append(self.starttag(node, "p"))
#.........这里部分代码省略.........
开发者ID:fedor4ever,项目名称:linux_build,代码行数:101,代码来源:htmlwriter.py


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