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


Python nodes.literal方法代码示例

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


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

示例1: setup

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def setup(app):
    def parse_node(env, text, node):
        args = text.split("^")
        name = args[0].strip()

        node += addnodes.literal_strong(name, name)

        if len(args) > 2:
            default = "={}".format(args[2].strip())
            node += nodes.literal(text=default)

        if len(args) > 1:
            content = "({})".format(args[1].strip())
            node += addnodes.compact_paragraph(text=content)

        return name  # this will be the link

    app.add_object_type(
        directivename="conf",
        rolename="conf",
        objname="configuration value",
        indextemplate="pair: %s; configuration value",
        parse_node=parse_node,
    ) 
开发者ID:tox-dev,项目名称:tox,代码行数:26,代码来源:conf.py

示例2: visit_Text

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def visit_Text(self, node):
        parent = node.parent
        while parent:
            if isinstance(parent, node_blacklist):
                return
            parent = parent.parent
        rawtext = node.rawsource
        data = rawtext.split("@@")
        if len(data) == 1:
            return
        nodes = []
        for i in range(len(data)):
            text = data[i]
            if i % 2 == 0:
                nodes.append(Text(text))
            else:
                formula = eval(text, pygrim.__dict__)
                latex = formula.latex()
                #nodes.append(literal(text, text))
                nodes.append(math(latex, Text(latex)))
                #nodes.append(math_block(latex, Text(latex)))
        node.parent.replace(node, nodes) 
开发者ID:fredrik-johansson,项目名称:fungrim,代码行数:24,代码来源:grinx.py

示例3: default_departure

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def default_departure(self, node):
        """Default node depart method."""
        self.level -= 1
        if not self.in_simple:
            self.output.append(self.indent*self.level)
        self.output.append(node.endtag())
        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)


    # specific visit and depart methods
    # --------------------------------- 
开发者ID:skarlekar,项目名称:faces,代码行数:18,代码来源:docutils_xml.py

示例4: definition_list_item

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def definition_list_item(self, termline):
        indented, indent, line_offset, blank_finish = \
              self.state_machine.get_indented()
        itemnode = nodes.definition_list_item(
            '\n'.join(termline + list(indented)))
        lineno = self.state_machine.abs_line_number() - 1
        (itemnode.source,
         itemnode.line) = self.state_machine.get_source_and_line(lineno)
        termlist, messages = self.term(termline, lineno)
        itemnode += termlist
        definition = nodes.definition('', *messages)
        itemnode += definition
        if termline[0][-2:] == '::':
            definition += self.reporter.info(
                  'Blank line missing before literal block (after the "::")? '
                  'Interpreted as a definition list item.',
                  line=lineno+1)
        self.nested_parse(indented, input_offset=line_offset, node=definition)
        return itemnode, blank_finish 
开发者ID:skarlekar,项目名称:faces,代码行数:21,代码来源:states.py

示例5: add_class_def

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def add_class_def(node, classDef):
    """Add reference on classDef to node """

    ref = addnodes.pending_xref(
        reftarget=classDef,
        reftype="class",
        refdomain="py",  # py:class="None" py:module="altair" refdoc="user_guide/marks"
        refexplicit=False,
        # refdoc="",
        refwarn=False,
    )
    ref["py:class"] = "None"
    ref["py:module"] = "altair"

    ref += nodes.literal(text=classDef, classes=["xref", "py", "py-class"])
    node += ref
    return node 
开发者ID:altair-viz,项目名称:altair,代码行数:19,代码来源:schematable.py

示例6: meth_ref_node

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def meth_ref_node(docname, ref_to, title=None):
    """Generate a node that references a :py:meth:"""
    if title is None:
        title = ref_to
    txt = Text(title, rawsource=title)
    newchild = literal(
        ':py:meth:`%s`' % ref_to,
        '',
        txt,
        classes=['xref', 'py', 'py-meth']
    )
    newnode = pending_xref(
        ':py:meth:`%s`' % ref_to,
        newchild,
        reftype='meth',
        refwarn='True',
        reftarget=ref_to,
        refexplicit='False',
        refdomain='py',
        refdoc=docname
    )
    return newnode 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:24,代码来源:conf.py

示例7: handle_signature

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def handle_signature(self, sig, signode):
        name = sig
        config = self.options.get('config', self.env.ref_context.get('cfg:config', ""))
        if not config:
            logger.warning("config option with unknown config", location=signode)
            config = "UNKNOWN"
        fullname = config + '.' + name

        signode += addnodes.desc_annotation('option ', 'option ')
        if not self.env.ref_context.get('cfg:in-config', False):
            signode += addnodes.pending_xref(sig,
                                             addnodes.desc_addname(config, config),
                                             refdomain='cfg',
                                             reftype='config',
                                             reftarget=config)
            signode += addnodes.desc_addname('', '.')

        signode += addnodes.desc_name(sig, '', nodes.Text(sig))

        typ = self.options.get('type')
        if typ:
            type_node = addnodes.desc_annotation(': ', ': ')
            info = self.content.parent.info(1)  # might be off by a few lines...
            type_node.extend(_parse_inline(self.state, typ, info))
            signode += type_node

        defaultvalue = self.options.get('default')
        if defaultvalue:
            val_node = addnodes.desc_annotation(' = ', ' = ')
            val_node += nodes.literal(defaultvalue, defaultvalue)
            signode += val_node

        return fullname, config 
开发者ID:tenpy,项目名称:tenpy,代码行数:35,代码来源:sphinx_cfg_options.py

示例8: create_option_reference_table_row

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def create_option_reference_table_row(self, option, config, context):
        row = nodes.row("")
        par = self.create_option_reference(option, config, context)
        row += nodes.entry("", par)
        if self.builder.config.cfg_options_default_in_summary_table:
            par = nodes.paragraph()
            if option.default:
                par += nodes.literal(option.default, option.default)
            row += nodes.entry("", par)
        par = nodes.paragraph()
        par += nodes.Text(option.summary)
        if option.summarycropped:
            par += self.make_refnode(option.docname, option.anchor, nodes.Text(" [...]"))
        row += nodes.entry("", par)
        return row 
开发者ID:tenpy,项目名称:tenpy,代码行数:17,代码来源:sphinx_cfg_options.py

示例9: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def run(self):
        """Create a type list."""
        config = self.state.document.settings.env.config

        # Group processes by category
        processes = get_processes(
            config.autoprocess_process_dir, config.autoprocess_source_base_url
        )
        processes.sort(key=itemgetter("type"))
        processes_by_types = {
            k: list(g) for k, g in groupby(processes, itemgetter("type"))
        }

        listnode = nodes.bullet_list()

        for typ in sorted(processes_by_types.keys()):
            par = nodes.paragraph()
            par += nodes.literal(typ, typ)
            par += nodes.Text(" - ")

            processes = sorted(processes_by_types[typ], key=itemgetter("name"))
            last_process = processes[-1]
            for process in processes:
                node = nodes.reference("", process["name"], internal=True)
                node["refuri"] = (
                    config.autoprocess_definitions_uri + "#process-" + process["slug"]
                )
                node["reftitle"] = process["name"]
                par += node
                if process != last_process:
                    par += nodes.Text(", ")

            listnode += nodes.list_item("", par)

        return [listnode] 
开发者ID:genialis,项目名称:resolwe,代码行数:37,代码来源:autoprocess.py

示例10: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def run(self):
        set_classes(self.options)
        self.assert_has_content()
        # join lines, separate blocks
        content = '\n'.join(self.content).split('\n\n')
        nodes = []
        for block in content:
            nodes.append(Text("Input: "))
            nodes.append(literal(block, Text(block)))
            formula = eval(block, pygrim.__dict__)
            latex = formula.latex()
            latex = "$$" + latex + "$$"
            node = math_block(latex, Text(latex), **self.options)
            node.attributes['nowrap'] = True
            nodes.append(node)
        return nodes

        '''
        for block in content:
            if not block:
                continue
            print("DUMB", type(self.block_text), type(block))
            #node = nodes.math_block(self.block_text, Text(block), **self.options)
            #node.line = self.content_offset + 1
            #self.add_name(node)
            _nodes.append(Text(self.block_text))
            #_nodes.append(node)
        return _nodes
        ''' 
开发者ID:fredrik-johansson,项目名称:fungrim,代码行数:31,代码来源:grinx.py

示例11: get_tokens

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
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()) 
开发者ID:skarlekar,项目名称:faces,代码行数:16,代码来源:universal.py

示例12: code_role

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
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], [] 
开发者ID:skarlekar,项目名称:faces,代码行数:30,代码来源:roles.py

示例13: literal

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
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 
开发者ID:skarlekar,项目名称:faces,代码行数:7,代码来源:states.py

示例14: doctest

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
def doctest(self, match, context, next_state):
        data = '\n'.join(self.state_machine.get_text_block())
        # TODO: prepend class value ['pycon'] (Python Console)
        # parse with `directives.body.CodeBlock` (returns literal-block
        # with class "code" and syntax highlight markup).
        self.parent += nodes.doctest_block(data, data)
        return [], next_state, [] 
开发者ID:skarlekar,项目名称:faces,代码行数:9,代码来源:states.py

示例15: text

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import literal [as 别名]
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 
开发者ID:skarlekar,项目名称:faces,代码行数:9,代码来源:states.py


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