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


Python directives.uri方法代码示例

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


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

示例1: visit_image

# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def visit_image(self, node):
        atts = {}
        uri = node['uri']
        filename = os.path.basename(uri)
        atts['alt'] = node.get('alt', uri)
        atts['thumbnail'] = 'true'

        if 'width' in node:
            atts['width'] = node['width']

        if 'name' in node:
            atts['title'] = node['name']

        if (isinstance(node.parent, nodes.TextElement) or
            (isinstance(node.parent, nodes.reference) and
             not isinstance(node.parent.parent, nodes.TextElement))):
            # Inline context or surrounded by <a>...</a>.
            suffix = ''
        else:
            suffix = '\n'

        self.context.append('')
        self.body.append(self.imgtag(filename, suffix, **atts)) 
开发者ID:Arello-Mobile,项目名称:sphinx-confluence,代码行数:25,代码来源:__init__.py

示例2: run

# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
        # we create a new cell and add uri reference to specified file and we add it to the node tree
        node = jupyter_node()
        node['uri'] = directives.uri(self.arguments[0])
        # we return the result
        return [node] 
开发者ID:QuantEcon,项目名称:sphinxcontrib-jupyter,代码行数:8,代码来源:jupyter.py

示例3: run

# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
        # remove 'align' processing
        # remove 'target' processing

        self.options.pop('align', None)
        reference = directives.uri(self.arguments[0])
        self.options['uri'] = reference
        set_classes(self.options)
        image_node = nodes.image(self.block_text, **self.options)
        self.add_name(image_node)
        return [image_node] 
开发者ID:Arello-Mobile,项目名称:sphinx-confluence,代码行数:13,代码来源:__init__.py

示例4: run

# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
        if 'align' in self.options:
            if isinstance(self.state, states.SubstitutionDef):
                # Check for align_v_values.
                if self.options['align'] not in self.align_v_values:
                    raise self.error(
                        'Error in "%s" directive: "%s" is not a valid value '
                        'for the "align" option within a substitution '
                        'definition.  Valid values for "align" are: "%s".'
                        % (self.name, self.options['align'],
                           '", "'.join(self.align_v_values)))
            elif self.options['align'] not in self.align_h_values:
                raise self.error(
                    'Error in "%s" directive: "%s" is not a valid value for '
                    'the "align" option.  Valid values for "align" are: "%s".'
                    % (self.name, self.options['align'],
                       '", "'.join(self.align_h_values)))
        messages = []
        reference = directives.uri(self.arguments[0])
        self.options['uri'] = reference
        reference_node = None
        if 'target' in self.options:
            block = states.escape2null(
                self.options['target']).splitlines()
            block = [line for line in block]
            target_type, data = self.state.parse_target(
                block, self.block_text, self.lineno)
            if target_type == 'refuri':
                reference_node = nodes.reference(refuri=data)
            elif target_type == 'refname':
                reference_node = nodes.reference(
                    refname=fully_normalize_name(data),
                    name=whitespace_normalize_name(data))
                reference_node.indirect_reference_name = data
                self.state.document.note_refname(reference_node)
            else:                           # malformed target
                messages.append(data)       # data is a system message
            del self.options['target']
        set_classes(self.options)
        image_node = nodes.image(self.block_text, **self.options)
        self.add_name(image_node)
        if reference_node:
            reference_node += image_node
            return messages + [reference_node]
        else:
            return messages + [image_node] 
开发者ID:skarlekar,项目名称:faces,代码行数:48,代码来源:images.py

示例5: run

# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
        node = nodes.Element()
        node.document = self.state.document
        env = self.state.document.settings.env
        docname = env.docname
        template_filename = self.options.get("file")
        debug_template = self.options.get("debug")
        cxt = (self.app.config.jinja_contexts[self.arguments[0]].copy()
               if self.arguments else {})
        cxt["options"] = {
            "header_char": self.options.get("header_char")
        }
        if template_filename:
            if debug_template is not None:
                print('')
                print('********** Begin Jinja Debug Output: Template Before Processing **********')
                print('********** From {} **********'.format(docname))
                reference_uri = directives.uri(os.path.join('source', template_filename))
                template_path = urllib.url2pathname(reference_uri)
                encoded_path = template_path.encode(sys.getfilesystemencoding())
                imagerealpath = os.path.abspath(encoded_path)
                with codecs.open(imagerealpath, encoding='utf-8') as f:
                    print(f.read())
                print('********** End Jinja Debug Output: Template Before Processing **********')
                print('')
            tpl = Environment(
                          loader=FileSystemLoader(
                              self.app.config.jinja_base, followlinks=True)
                      ).get_template(template_filename)
        else:
            if debug_template is not None:
                print('')
                print('********** Begin Jinja Debug Output: Template Before Processing **********')
                print('********** From {} **********'.format(docname))
                print('\n'.join(self.content))
                print('********** End Jinja Debug Output: Template Before Processing **********')
                print('')
            tpl = Environment(
                      loader=FileSystemLoader(
                          self.app.config.jinja_base, followlinks=True)
                  ).from_string('\n'.join(self.content))
        new_content = tpl.render(**cxt)
        if debug_template is not None:
            print('')
            print('********** Begin Jinja Debug Output: Template After Processing **********')
            print(new_content)
            print('********** End Jinja Debug Output: Template After Processing **********')
            print('')
        new_content = StringList(new_content.splitlines(), source='')
        sphinx.util.nested_parse_with_titles(
            self.state, new_content, node)
        return node.children 
开发者ID:tardyp,项目名称:sphinx-jinja,代码行数:54,代码来源:jinja.py


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