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


Python html5_polyglot.HTMLTranslator类代码示例

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


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

示例1: visit_title

 def visit_title(self, node):
     # type: (nodes.Node) -> None
     BaseTranslator.visit_title(self, node)
     self.add_secnumber(node)
     self.add_fignumber(node.parent)
     if isinstance(node.parent, nodes.table):
         self.body.append('<span class="caption-text">')
开发者ID:atodorov,项目名称:sphinx,代码行数:7,代码来源:html5.py

示例2: visit_caption

 def visit_caption(self, node):
     # type: (nodes.Node) -> None
     if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
         self.body.append('<div class="code-block-caption">')
     else:
         BaseTranslator.visit_caption(self, node)
     self.add_fignumber(node.parent)
     self.body.append(self.starttag(node, 'span', '', CLASS='caption-text'))
开发者ID:atodorov,项目名称:sphinx,代码行数:8,代码来源:html5.py

示例3: visit_literal_block

    def visit_literal_block(self, node):
        # type: (nodes.Node) -> None
        if node.rawsource != node.astext():
            # most probably a parsed-literal block -- don't highlight
            return BaseTranslator.visit_literal_block(self, node)
        lang = self.highlightlang
        linenos = node.rawsource.count('\n') >= \
            self.highlightlinenothreshold - 1
        highlight_args = node.get('highlight_args', {})
        if 'language' in node:
            # code-block directives
            lang = node['language']
            highlight_args['force'] = True
        if 'linenos' in node:
            linenos = node['linenos']
        if lang is self.highlightlang_base:
            # only pass highlighter options for original language
            opts = self.highlightopts
        else:
            opts = {}

        highlighted = self.highlighter.highlight_block(
            node.rawsource, lang, opts=opts, linenos=linenos,
            location=(self.builder.current_docname, node.line), **highlight_args
        )
        starttag = self.starttag(node, 'div', suffix='',
                                 CLASS='highlight-%s' % lang)
        self.body.append(starttag + highlighted + '</div>\n')
        raise nodes.SkipNode
开发者ID:atodorov,项目名称:sphinx,代码行数:29,代码来源:html5.py

示例4: depart_caption

    def depart_caption(self, node):
        # type: (nodes.Node) -> None
        self.body.append('</span>')

        # append permalink if available
        if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
            self.add_permalink_ref(node.parent, _('Permalink to this code'))
        elif isinstance(node.parent, nodes.figure):
            image_nodes = node.parent.traverse(nodes.image)
            target_node = image_nodes and image_nodes[0] or node.parent
            self.add_permalink_ref(target_node, _('Permalink to this image'))
        elif node.parent.get('toctree'):
            self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree'))

        if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
            self.body.append('</div>\n')
        else:
            BaseTranslator.depart_caption(self, node)
开发者ID:atodorov,项目名称:sphinx,代码行数:18,代码来源:html5.py

示例5: __init__

 def __init__(self, builder, *args, **kwds):
     # type: (StandaloneHTMLBuilder, Any, Any) -> None
     BaseTranslator.__init__(self, *args, **kwds)
     self.highlighter = builder.highlighter
     self.builder = builder
     self.docnames = [builder.current_docname]  # for singlehtml builder
     self.manpages_url = builder.config.manpages_url
     self.protect_literal_text = 0
     self.permalink_text = builder.config.html_add_permalinks
     # support backwards-compatible setting to a bool
     if not isinstance(self.permalink_text, string_types):
         self.permalink_text = self.permalink_text and u'\u00B6' or ''
     self.permalink_text = self.encode(self.permalink_text)
     self.secnumber_suffix = builder.config.html_secnumber_suffix
     self.param_separator = ''
     self.optional_param_level = 0
     self._table_row_index = 0
     self.required_params_left = 0
开发者ID:willingc,项目名称:sphinx,代码行数:18,代码来源:html5.py

示例6: should_be_compact_paragraph

 def should_be_compact_paragraph(self, node):
     # type: (nodes.Node) -> bool
     """Determine if the <p> tags around paragraph can be omitted."""
     if isinstance(node.parent, addnodes.desc_content):
         # Never compact desc_content items.
         return False
     if isinstance(node.parent, addnodes.versionmodified):
         # Never compact versionmodified nodes.
         return False
     return BaseTranslator.should_be_compact_paragraph(self, node)
开发者ID:atodorov,项目名称:sphinx,代码行数:10,代码来源:html5.py

示例7: depart_title

    def depart_title(self, node):
        # type: (nodes.Node) -> None
        close_tag = self.context[-1]
        if (self.permalink_text and self.builder.add_permalinks and
           node.parent.hasattr('ids') and node.parent['ids']):
            # add permalink anchor
            if close_tag.startswith('</h'):
                self.add_permalink_ref(node.parent, _('Permalink to this headline'))
            elif close_tag.startswith('</a></h'):
                self.body.append(u'</a><a class="headerlink" href="#%s" ' %
                                 node.parent['ids'][0] +
                                 u'title="%s">%s' % (
                                     _('Permalink to this headline'),
                                     self.permalink_text))
            elif isinstance(node.parent, nodes.table):
                self.body.append('</span>')
                self.add_permalink_ref(node.parent, _('Permalink to this table'))
        elif isinstance(node.parent, nodes.table):
            self.body.append('</span>')

        BaseTranslator.depart_title(self, node)
开发者ID:atodorov,项目名称:sphinx,代码行数:21,代码来源:html5.py

示例8: visit_image

    def visit_image(self, node):
        # type: (nodes.Node) -> None
        olduri = node['uri']
        # rewrite the URI if the environment knows about it
        if olduri in self.builder.images:
            node['uri'] = posixpath.join(self.builder.imgpath,
                                         self.builder.images[olduri])

        uri = node['uri']
        if uri.lower().endswith(('svg', 'svgz')):
            atts = {'src': uri}
            if 'width' in node:
                atts['width'] = node['width']
            if 'height' in node:
                atts['height'] = node['height']
            atts['alt'] = node.get('alt', uri)
            if 'align' in node:
                self.body.append('<div align="%s" class="align-%s">' %
                                 (node['align'], node['align']))
                self.context.append('</div>\n')
            else:
                self.context.append('')
            self.body.append(self.emptytag(node, 'img', '', **atts))
            return

        if 'scale' in node:
            # Try to figure out image height and width.  Docutils does that too,
            # but it tries the final file name, which does not necessarily exist
            # yet at the time the HTML file is written.
            if not ('width' in node and 'height' in node):
                size = get_image_size(os.path.join(self.builder.srcdir, olduri))
                if size is None:
                    logger.warning('Could not obtain image size. :scale: option is ignored.',
                                   location=node)
                else:
                    if 'width' not in node:
                        node['width'] = str(size[0])
                    if 'height' not in node:
                        node['height'] = str(size[1])
        BaseTranslator.visit_image(self, node)
开发者ID:atodorov,项目名称:sphinx,代码行数:40,代码来源:html5.py

示例9: visit_literal_block

    def visit_literal_block(self, node):
        # type: (nodes.Node) -> None
        if node.rawsource != node.astext():
            # most probably a parsed-literal block -- don't highlight
            return BaseTranslator.visit_literal_block(self, node)

        lang = node.get('language', 'default')
        linenos = node.get('linenos', False)
        highlight_args = node.get('highlight_args', {})
        highlight_args['force'] = node.get('force_highlighting', False)
        if lang is self.builder.config.highlight_language:
            # only pass highlighter options for original language
            opts = self.builder.config.highlight_options
        else:
            opts = {}

        highlighted = self.highlighter.highlight_block(
            node.rawsource, lang, opts=opts, linenos=linenos,
            location=(self.builder.current_docname, node.line), **highlight_args
        )
        starttag = self.starttag(node, 'div', suffix='',
                                 CLASS='highlight-%s notranslate' % lang)
        self.body.append(starttag + highlighted + '</div>\n')
        raise nodes.SkipNode
开发者ID:willingc,项目名称:sphinx,代码行数:24,代码来源:html5.py

示例10: visit_field_list

 def visit_field_list(self, node):
     # type: (nodes.Node) -> None
     self._fieldlist_row_index = 0
     return BaseTranslator.visit_field_list(self, node)
开发者ID:atodorov,项目名称:sphinx,代码行数:4,代码来源:html5.py

示例11: depart_image

 def depart_image(self, node):
     # type: (nodes.Node) -> None
     if node['uri'].lower().endswith(('svg', 'svgz')):
         self.body.append(self.context.pop())
     else:
         BaseTranslator.depart_image(self, node)
开发者ID:atodorov,项目名称:sphinx,代码行数:6,代码来源:html5.py

示例12: visit_bullet_list

 def visit_bullet_list(self, node):
     # type: (nodes.Node) -> None
     if len(node) == 1 and node[0].tagname == 'toctree':
         # avoid emitting empty <ul></ul>
         raise nodes.SkipNode
     BaseTranslator.visit_bullet_list(self, node)
开发者ID:atodorov,项目名称:sphinx,代码行数:6,代码来源:html5.py

示例13: __init__

 def __init__(self, doc):
     BaseTranslator.__init__(self, doc)
开发者ID:akrylysov,项目名称:yozuch,代码行数:2,代码来源:rstparser.py


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