Python docutils.nodes.literal() Examples
The following are 30
code examples of docutils.nodes.literal().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
docutils.nodes
, or try the search function
.
Example #1
Source File: conf.py From tox with MIT License | 6 votes |
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, )
Example #2
Source File: docutils_xml.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
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 # ---------------------------------
Example #3
Source File: docutils_xml.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
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 # ---------------------------------
Example #4
Source File: states.py From faces with GNU General Public License v2.0 | 6 votes |
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
Example #5
Source File: states.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #6
Source File: states.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
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
Example #7
Source File: docutils_xml.py From faces with GNU General Public License v2.0 | 6 votes |
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 # ---------------------------------
Example #8
Source File: docutils_xml.py From deepWordBug with Apache License 2.0 | 6 votes |
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 # ---------------------------------
Example #9
Source File: schematable.py From altair with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #10
Source File: docutils_xml.py From bash-lambda-layer with MIT License | 6 votes |
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 # ---------------------------------
Example #11
Source File: grinx.py From fungrim with MIT License | 6 votes |
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)
Example #12
Source File: docutils_xml.py From blackmamba with MIT License | 6 votes |
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 # ---------------------------------
Example #13
Source File: conf.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
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
Example #14
Source File: sphinx_cfg_options.py From tenpy with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: universal.py From aws-extender with MIT License | 5 votes |
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())
Example #16
Source File: states.py From blackmamba with MIT License | 5 votes |
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, []
Example #17
Source File: states.py From blackmamba with MIT License | 5 votes |
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
Example #18
Source File: roles.py From blackmamba with MIT License | 5 votes |
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], []
Example #19
Source File: universal.py From blackmamba with MIT License | 5 votes |
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())
Example #20
Source File: states.py From blackmamba with MIT License | 5 votes |
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
Example #21
Source File: states.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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
Example #22
Source File: roles.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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], []
Example #23
Source File: states.py From bash-lambda-layer with MIT License | 5 votes |
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, []
Example #24
Source File: universal.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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())
Example #25
Source File: states.py From bash-lambda-layer with MIT License | 5 votes |
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
Example #26
Source File: docutils_xml.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #27
Source File: docutils_xml.py From bash-lambda-layer with MIT License | 5 votes |
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)
Example #28
Source File: states.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
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, []
Example #29
Source File: universal.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
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())
Example #30
Source File: states.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
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