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


Python方法docutils.nodes.Node代码示例

以下是Python方法docutils.nodes.Node的代码示例。如果您正苦于以下问题:Python nodes.Node方法的具体用法?Python nodes.Node怎么用?Python nodes.Node使用的例子?那么恭喜您, 这里整理的方法代码示例例程将为您提供帮助。您也可以进一步了解该方法所在模块docutils.nodes的用法示例。

本文一共展示了nodes.Node的8个开源代码实例,这些例子默认根据受欢迎程度排序。您可以为喜欢的代码打CALL点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _get_matching_child

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def _get_matching_child(
        parent_node: nodes.Element, child_class: nodes.Element, last=True):
    """Get the first or last child node that matches a Node subclass.

    Args:
        parent_node: The node to find the child of.
        child_class: The Node subclass to check against.
        last: If True, find the last matching child. If False, find the first
            one.

    Returns:
        The first or last child Node object that is an instance of the given
        class.
    """
    if last:
        children = reversed(parent_node.children)
    else:
        children = parent_node.children

    for child_node in children:
        if isinstance(child_node, child_class):
            return child_node 
开发者ID:lostatc,项目:linotype,完整代码来源:ext.py


示例2: _make_visit_admonition

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def _make_visit_admonition(name):
        def visit_admonition(self, node):
            # type: (nodes.NodeVisitor, nodes.Node) -> None
            # self.end_state(first=admonitionlabels[name] + ': ')
            info("visit", node)
        return visit_admonition 
开发者ID:shibukawa,项目:sphinxcontrib-ssmlbuilder,完整代码来源:writer.py


示例3: visit_paragraph

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def visit_paragraph(self, node):
        # type: (nodes.Node) -> None
        if self.active():
            self.contents.append([0, JOIN_BEFORE, '<break time="%dms" />' % self.builder.ssml_break_after_paragraph])
        info("visit", node) 
开发者ID:shibukawa,项目:sphinxcontrib-ssmlbuilder,完整代码来源:writer.py


示例4: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def run(self) -> List[nodes.Node]:
        """Run the directive.

        Returns:
            A list of Node objects.
        """
        root_item = self._retrieve_item()

        if "item_id" in self.options:
            root_item = root_item.get_item_by_id(
                self.options["item_id"], raising=True)

        if "children" in self.options:
            root_item.parent = None

        # Parse directive and get content to extend items with.
        nested_nodes = nodes.paragraph()
        self.state.nested_parse(
            self.content, self.content_offset, nested_nodes)
        def_list = _get_matching_child(
            nested_nodes, nodes.definition_list, last=False)
        if def_list is not None:
            definitions = _parse_definition_list(def_list)
        else:
            definitions = collections.defaultdict(lambda: None)

        return self._parse_tree(root_item, definitions) 
开发者ID:lostatc,项目:linotype,完整代码来源:ext.py


示例5: figure_wrapper

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def figure_wrapper(directive, node, caption):
    # type: (Directive, nodes.Node, unicode) -> nodes.figure
    figure_node = nodes.figure('', node)
    if 'align' in node:
        figure_node['align'] = node.attributes.pop('align')

    parsed = nodes.Element()
    directive.state.nested_parse(ViewList([caption], source=''),
                                 directive.content_offset, parsed)
    caption_node = nodes.caption(parsed[0].rawsource, '',
                                 *parsed[0].children)
    caption_node.source = parsed[0].source
    caption_node.line = parsed[0].line
    figure_node += caption_node
    return figure_node 
开发者ID:kevinpt,项目:symbolator,完整代码来源:symbolator_sphinx.py


示例6: run_directive

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def run_directive(self, directive, match, type_name, option_presets):
        """
        Parse a directive then run its directive function.

        Parameters:

        - `directive`: The class implementing the directive.  Must be
          a subclass of `rst.Directive`.

        - `match`: A regular expression match object which matched the first
          line of the directive.

        - `type_name`: The directive name, as used in the source text.

        - `option_presets`: A dictionary of preset options, defaults for the
          directive options.  Currently, only an "alt" option is passed by
          substitution definitions (value: the substitution name), which may
          be used by an embedded image directive.

        Returns a 2-tuple: list of nodes, and a "blank finish" boolean.
        """
        if isinstance(directive, (FunctionType, MethodType)):
            from docutils.parsers.rst import convert_directive_function
            directive = convert_directive_function(directive)
        lineno = self.state_machine.abs_line_number()
        initial_line_offset = self.state_machine.line_offset
        indented, indent, line_offset, blank_finish \
                  = self.state_machine.get_first_known_indented(match.end(),
                                                                strip_top=0)
        block_text = '\n'.join(self.state_machine.input_lines[
            initial_line_offset : self.state_machine.line_offset + 1])
        try:
            arguments, options, content, content_offset = (
                self.parse_directive_block(indented, line_offset,
                                           directive, option_presets))
        except MarkupError, detail:
            error = self.reporter.error(
                'Error in "%s" directive:\n%s.' % (type_name,
                                                   ' '.join(detail.args)),
                nodes.literal_block(block_text, block_text), line=lineno)
            return [error], blank_finish
        directive_instance = directive(
            type_name, arguments, options, content, lineno,
            content_offset, block_text, self, self.state_machine)
        try:
            result = directive_instance.run()
        except docutils.parsers.rst.DirectiveError, error:
            msg_node = self.reporter.system_message(error.level, error.msg,
                                                    line=lineno)
            msg_node += nodes.literal_block(block_text, block_text)
            result = [msg_node]
        assert isinstance(result, list), \
               'Directive "%s" must return a list of nodes.' % type_name
        for i in range(len(result)):
            assert isinstance(result[i], nodes.Node), \
                   ('Directive "%s" returned non-Node object (index %s): %r'
                    % (type_name, i, result[i]))
        return (result,
                blank_finish or self.state_machine.is_next_line_blank()) 
开发者ID:lordmuffin,项目:aws-cfn-plex,完整代码来源:states.py


示例7: run_directive

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def run_directive(self, directive, match, type_name, option_presets):
        """
        Parse a directive then run its directive function.

        Parameters:

        - `directive`: The class implementing the directive.  Must be
          a subclass of `rst.Directive`.

        - `match`: A regular expression match object which matched the first
          line of the directive.

        - `type_name`: The directive name, as used in the source text.

        - `option_presets`: A dictionary of preset options, defaults for the
          directive options.  Currently, only an "alt" option is passed by
          substitution definitions (value: the substitution name), which may
          be used by an embedded image directive.

        Returns a 2-tuple: list of nodes, and a "blank finish" boolean.
        """
        if isinstance(directive, (FunctionType, MethodType)):
            from docutils.parsers.rst import convert_directive_function
            directive = convert_directive_function(directive)
        lineno = self.state_machine.abs_line_number()
        initial_line_offset = self.state_machine.line_offset
        indented, indent, line_offset, blank_finish \
                  = self.state_machine.get_first_known_indented(match.end(),
                                                                strip_top=0)
        block_text = '\n'.join(self.state_machine.input_lines[
            initial_line_offset : self.state_machine.line_offset + 1])
        try:
            arguments, options, content, content_offset = (
                self.parse_directive_block(indented, line_offset,
                                           directive, option_presets))
        except MarkupError as detail:
            error = self.reporter.error(
                'Error in "%s" directive:\n%s.' % (type_name,
                                                   ' '.join(detail.args)),
                nodes.literal_block(block_text, block_text), line=lineno)
            return [error], blank_finish
        directive_instance = directive(
            type_name, arguments, options, content, lineno,
            content_offset, block_text, self, self.state_machine)
        try:
            result = directive_instance.run()
        except docutils.parsers.rst.DirectiveError as error:
            msg_node = self.reporter.system_message(error.level, error.msg,
                                                    line=lineno)
            msg_node += nodes.literal_block(block_text, block_text)
            result = [msg_node]
        assert isinstance(result, list), \
               'Directive "%s" must return a list of nodes.' % type_name
        for i in range(len(result)):
            assert isinstance(result[i], nodes.Node), \
                   ('Directive "%s" returned non-Node object (index %s): %r'
                    % (type_name, i, result[i]))
        return (result,
                blank_finish or self.state_machine.is_next_line_blank()) 
开发者ID:zrzka,项目:blackmamba,完整代码来源:states.py


示例8: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Node [as 别名]
def run(self):
        # type: () -> List[nodes.Node]
        if self.arguments:
            document = self.state.document
            if self.content:
                return [document.reporter.warning(
                    __('Symbolator directive cannot have both content and '
                    'a filename argument'), line=self.lineno)]
            env = self.state.document.settings.env
            argument = search_image_for_language(self.arguments[0], env)
            rel_filename, filename = env.relfn2path(argument)
            env.note_dependency(rel_filename)
            try:
                with codecs.open(filename, 'r', 'utf-8') as fp:
                    symbolator_code = fp.read()
            except (IOError, OSError):
                return [document.reporter.warning(
                    __('External Symbolator file %r not found or reading '
                    'it failed') % filename, line=self.lineno)]
        else:
            symbolator_code = '\n'.join(self.content)
            if not symbolator_code.strip():
                return [self.state_machine.reporter.warning(
                    __('Ignoring "symbolator" directive without content.'),
                    line=self.lineno)]
        node = symbolator()
        node['code'] = symbolator_code
        node['options'] = {}
        if 'symbolator_cmd' in self.options:
            node['options']['symbolator_cmd'] = self.options['symbolator_cmd']
        if 'alt' in self.options:
            node['alt'] = self.options['alt']
        if 'align' in self.options:
            node['align'] = self.options['align']
            
        if 'name' in self.options:
          node['options']['name'] = self.options['name']

        caption = self.options.get('caption')
        if caption:
            node = figure_wrapper(self, node, caption)

        self.add_name(node)
        return [node] 
开发者ID:kevinpt,项目:symbolator,完整代码来源:symbolator_sphinx.py



注:本文示例均筛选自Github等开源项目,代码版权请参考对应项目的License;未经允许,请勿转载。