python类literal()的实例源码

std.py 文件源码 项目:anarchy_sphinx 作者: AnarchyTools 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def token_xrefs(text):
    retnodes = []
    pos = 0
    for m in token_re.finditer(text):
        if m.start() > pos:
            txt = text[pos:m.start()]
            retnodes.append(nodes.Text(txt, txt))
        refnode = addnodes.pending_xref(
            m.group(1), reftype='token', refdomain='std', reftarget=m.group(1))
        refnode += nodes.literal(m.group(1), m.group(1), classes=['xref'])
        retnodes.append(refnode)
        pos = m.end()
    if pos < len(text):
        retnodes.append(nodes.Text(text[pos:], text[pos:]))
    return retnodes
universal.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_tokens(self, txtnodes):
        # A generator that yields ``(texttype, nodetext)`` tuples for a list
        # of "Text" nodes (interface to ``smartquotes.educate_tokens()``).

        texttype = {True: 'literal', # "literal" text is not changed:
                    False: 'plain'}
        for txtnode in txtnodes:
            nodetype = texttype[isinstance(txtnode.parent,
                                           (nodes.literal,
                                            nodes.math,
                                            nodes.image,
                                            nodes.raw,
                                            nodes.problematic))]
            yield (nodetype, txtnode.astext())
states.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def literal(self, match, lineno):
        before, inlines, remaining, sysmessages, endstring = self.inline_obj(
              match, lineno, self.patterns.literal, nodes.literal,
              restore_backslashes=True)
        return before, inlines, remaining, sysmessages
states.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def text(self, match, context, next_state):
        if context:
            self.messages.append(
                self.reporter.error('Inconsistent literal block quoting.',
                                   line=self.state_machine.abs_line_number()))
            self.state_machine.previous_line()
        raise EOFError
transforms.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def visit_pending_xref(self, node):
        text = node.astext()
        self.parent.append(nodes.literal(text, text))
        raise nodes.SkipNode
std.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def token_xrefs(text):
    retnodes = []
    pos = 0
    for m in token_re.finditer(text):
        if m.start() > pos:
            txt = text[pos:m.start()]
            retnodes.append(nodes.Text(txt, txt))
        refnode = addnodes.pending_xref(
            m.group(1), reftype='token', refdomain='std', reftarget=m.group(1))
        refnode += nodes.literal(m.group(1), m.group(1), classes=['xref'])
        retnodes.append(refnode)
        pos = m.end()
    if pos < len(text):
        retnodes.append(nodes.Text(text[pos:], text[pos:]))
    return retnodes
roles.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def emph_literal_role(typ, rawtext, text, lineno, inliner,
                      options={}, content=[]):
    text = utils.unescape(text)
    pos = 0
    retnode = nodes.literal(role=typ.lower(), classes=[typ])
    for m in _litvar_re.finditer(text):
        if m.start() > pos:
            txt = text[pos:m.start()]
            retnode += nodes.Text(txt, txt)
        retnode += nodes.emphasis(m.group(1), m.group(1))
        pos = m.end()
    if pos < len(text):
        retnode += nodes.Text(text[pos:], text[pos:])
    return [retnode], []
manpage.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def apply(self):
        def is_inline(node):
            return isinstance(node, (nodes.literal, nodes.emphasis, nodes.strong))

        for node in self.document.traverse(is_inline):
            if any(is_inline(subnode) for subnode in node):
                pos = node.parent.index(node)
                for subnode in reversed(node[1:]):
                    node.remove(subnode)
                    if is_inline(subnode):
                        node.parent.insert(pos + 1, subnode)
                    else:
                        newnode = node.__class__('', subnode, **node.attributes)
                        node.parent.insert(pos + 1, newnode)
coqdomain.py 文件源码 项目:coq-rst 作者: cpitclaudel 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def NotationRole(role, rawtext, text, lineno, inliner, options={}, content=[]):
    #pylint: disable=unused-argument, dangerous-default-value
    """And inline role for notations"""
    notation = utils.unescape(text, 1)
    position = inliner.reporter.get_source_and_line(lineno)
    return [nodes.literal(rawtext, '', parse_notation(notation, *position, rawtext=rawtext))], []
coqdomain.py 文件源码 项目:coq-rst 作者: cpitclaudel 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def run(self):
        # Uses a ‘container’ instead of a ‘literal_block’ to disable
        # Pygments-based post-processing (we could also set rawsource to '')
        content = '\n'.join(self.content)
        options = self.arguments[0].split() if self.arguments else ['in']
        if 'all' in options:
            options.extend(['in', 'out'])
        node = nodes.container(content, coqtop_options = list(set(options)),
                               classes=['coqtop', 'literal-block'])
        self.add_name(node)
        return [node]
coqdomain.py 文件源码 项目:coq-rst 作者: cpitclaudel 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(self):
        # Uses a ‘container’ instead of a ‘literal_block’ to disable
        # Pygments-based post-processing (we could also set rawsource to '')
        content = '\n'.join(self.content)
        node = nodes.inline(content, '', *highlight_using_coqdoc(content))
        wrapper = nodes.container(content, node, classes=['coqdoc', 'literal-block'])
        return [wrapper]
support_matrix.py 文件源码 项目:nova-dpm 作者: openstack 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _create_cli_paragraph(self, feature):
        ''' Create a paragraph which represents the CLI commands of the feature

        The paragraph will have a bullet list of CLI commands.
        '''
        para = nodes.paragraph()
        para.append(nodes.strong(text="CLI commands:"))
        commands = nodes.bullet_list()
        for c in feature.cli.split(";"):
            cli_command = nodes.list_item()
            cli_command += nodes.literal(text=c, classes=["sp_cli"])
            commands.append(cli_command)
        para.append(commands)
        return para
universal.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_tokens(self, txtnodes):
        # A generator that yields ``(texttype, nodetext)`` tuples for a list
        # of "Text" nodes (interface to ``smartquotes.educate_tokens()``).

        texttype = {True: 'literal', # "literal" text is not changed:
                    False: 'plain'}
        for txtnode in txtnodes:
            nodetype = texttype[isinstance(txtnode.parent,
                                           self.literal_nodes)]
            yield (nodetype, txtnode.astext())
docutils_xml.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def default_visit(self, node):
        """Default node visit method."""
        if not self.in_simple:
            self.output.append(self.indent*self.level)
        self.output.append(node.starttag(xml.sax.saxutils.quoteattr))
        self.level += 1
        # @@ make nodes.literal an instance of FixedTextElement?
        if isinstance(node, (nodes.FixedTextElement, nodes.literal)):
            self.fixed_text += 1
        if isinstance(node, self.simple_nodes):
            self.in_simple += 1
        if not self.in_simple:
            self.output.append(self.newline)
states.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def literal(self, match, lineno):
        before, inlines, remaining, sysmessages, endstring = self.inline_obj(
              match, lineno, self.patterns.literal, nodes.literal,
              restore_backslashes=True)
        return before, inlines, remaining, sysmessages
states.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def text(self, match, context, next_state):
        if context:
            self.messages.append(
                self.reporter.error('Inconsistent literal block quoting.',
                                   line=self.state_machine.abs_line_number()))
            self.state_machine.previous_line()
        raise EOFError
roles.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    set_classes(options)
    language = options.get('language', '')
    classes = ['code']
    if 'classes' in options:
        classes.extend(options['classes'])
    if language and language not in classes:
        classes.append(language)
    try:
        tokens = Lexer(utils.unescape(text, 1), language,
                       inliner.document.settings.syntax_highlight)
    except LexerError as error:
        msg = inliner.reporter.warning(error)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]

    node = nodes.literal(rawtext, '', classes=classes)

    # analyse content and add nodes for every token
    for classes, value in tokens:
        # print (classes, value)
        if classes:
            node += nodes.inline(value, value, classes=classes)
        else:
            # insert as Text to decrease the verbosity of the output
            node += nodes.Text(value, value)

    return [node], []
click_autodoc.py 文件源码 项目:cuvner 作者: meejah 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def write_usage(self, prog, args='', prefix='Usage: '):
        """Writes a usage line into the buffer.

        :param prog: the program name.
        :param args: whitespace separated list of arguments.
        :param prefix: the prefix for the first line.
        """
        title = nodes.subtitle()
        title.append(nodes.literal('', '{} {}'.format(self._topname, prog)))
        usage = nodes.paragraph()
        usage.append(nodes.Text(prefix))
        usage.append(nodes.literal('', '{} {} {}'.format(self._topname, prog, args)))
        self._node.append(title)
        self._node.append(usage)
universal.py 文件源码 项目:RST-vscode 作者: tht13 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_tokens(self, txtnodes):
        # A generator that yields ``(texttype, nodetext)`` tuples for a list
        # of "Text" nodes (interface to ``smartquotes.educate_tokens()``).

        texttype = {True: 'literal', # "literal" text is not changed:
                    False: 'plain'}
        for txtnode in txtnodes:
            nodetype = texttype[isinstance(txtnode.parent,
                                           (nodes.literal,
                                            nodes.math,
                                            nodes.image,
                                            nodes.raw,
                                            nodes.problematic))]
            yield (nodetype, txtnode.astext())
docutils_xml.py 文件源码 项目:RST-vscode 作者: tht13 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def default_visit(self, node):
        """Default node visit method."""
        if not self.in_simple:
            self.output.append(self.indent*self.level)
        self.output.append(node.starttag(xml.sax.saxutils.quoteattr))
        self.level += 1
        # @@ make nodes.literal an instance of FixedTextElement?
        if isinstance(node, (nodes.FixedTextElement, nodes.literal)):
            self.fixed_text += 1
        if isinstance(node, self.simple_nodes):
            self.in_simple += 1
        if not self.in_simple:
            self.output.append(self.newline)


问题


面经


文章

微信
公众号

扫码关注公众号