Python docutils.nodes.inline() Examples
The following are 30
code examples of docutils.nodes.inline().
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 manheim-c7n-tools with Apache License 2.0 | 6 votes |
def label_ref_node(docname, ref_to, title): """Generate a node that references a label""" txt = Text(title, rawsource=title) newchild = inline( ':ref:`%s`' % ref_to, '', txt, classes=['xref', 'std', 'std-ref'] ) newnode = pending_xref( ':ref:`%s`' % ref_to, newchild, reftype='ref', refwarn='True', reftarget=ref_to, refexplicit='False', refdomain='std', refdoc=docname ) return newnode
Example #2
Source File: layout.py From sphinxcontrib-needs with MIT License | 6 votes |
def meta_id(self): """ Returns the current need id as clickable and linked reference. Usage:: <<meta_id()>> :return: docutils node """ from sphinx.util.nodes import make_refnode id_container = nodes.inline(classes=["needs-id"]) nodes_id_text = nodes.Text(self.need['id'], self.need['id']) id_ref = make_refnode(self.app.builder, # fromdocname=self.need['docname'], fromdocname=self.fromdocname, todocname=self.need['docname'], targetid=self.need['id'], child=nodes_id_text.deepcopy(), title=self.need['id']) id_container += id_ref return id_container
Example #3
Source File: citations.py From indra with BSD 2-Clause "Simplified" License | 6 votes |
def pmid_reference_role(role, rawtext, text, lineno, inliner, options={}, content=[]): try: pmid = int(text) if pmid <= 0: raise ValueError except ValueError: msg = inliner.reporter.error( 'pmid number must be a number greater than or equal to 1; ' '"%s" is invalid.' % text, line=lineno) prb = inliner.problematic(rawtext, rawtext, msg) return [prb], [msg] ref = pubmed_uri_pattern % pmid nodelist = [] nodelist.append(nodes.inline(text='PMID:')) nodelist.append(nodes.reference(rawtext, utils.unescape(text), refuri=ref, **options)) return nodelist, []
Example #4
Source File: conf.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
def label_ref_node(docname, ref_to, title): """Generate a node that references a label""" txt = Text(title, rawsource=title) newchild = inline( ':ref:`%s`' % ref_to, '', txt, classes=['xref', 'std', 'std-ref'] ) newnode = pending_xref( ':ref:`%s`' % ref_to, newchild, reftype='ref', refwarn='True', reftarget=ref_to, refexplicit='False', refdomain='std', refdoc=docname ) return newnode
Example #5
Source File: sphinx_directives.py From emva1288 with GNU General Public License v3.0 | 6 votes |
def run(self): idb = nodes.make_id("emva1288-" + self.options['section']) section = nodes.section(ids=[idb]) section += nodes.rubric(text='Emva1288') lst = nodes.bullet_list() for k in self.option_spec.keys(): if k not in self.options: continue item = nodes.list_item() item += nodes.strong(text=k + ':') item += nodes.inline(text=' ' + self.options[k]) lst += item section += lst return [section]
Example #6
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 #7
Source File: roles.py From bash-lambda-layer with MIT License | 5 votes |
def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). set_classes(options) return [nodes.inline(rawtext, utils.unescape(text), **options)], []
Example #8
Source File: roles.py From bash-lambda-layer 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 #9
Source File: numdoc.py From typescript-guide with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def numdoc_role(name, rawtext, text, lineno, inliner, options={}, content=[]): """Role for making latex ref to the doc head.""" env = inliner.document.settings.env text = utils.unescape(text) has_explicit, title, target = split_explicit_title(text) pnode = nodes.inline(rawtext, title, classes=['xref','doc']) pnode['reftarget'] = target return [pnode], []
Example #10
Source File: references.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def make_target_footnote(self, refuri, refs, notes): if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] else: # original footnote = nodes.footnote() footnote_id = self.document.set_id(footnote) # Use uppercase letters and a colon; they can't be # produced inside names by the parser. footnote_name = 'TARGET_NOTE: ' + footnote_id footnote['auto'] = 1 footnote['names'] = [footnote_name] footnote_paragraph = nodes.paragraph() footnote_paragraph += nodes.reference('', refuri, refuri=refuri) footnote += footnote_paragraph self.document.note_autofootnote(footnote) self.document.note_explicit_target(footnote, footnote) for ref in refs: if isinstance(ref, nodes.target): continue refnode = nodes.footnote_reference(refname=footnote_name, auto=1) refnode['classes'] += self.classes self.document.note_autofootnote_ref(refnode) self.document.note_footnote_ref(refnode) index = ref.parent.index(ref) + 1 reflist = [refnode] if not utils.get_trim_footnote_ref_space(self.document.settings): if self.classes: reflist.insert(0, nodes.inline(text=' ', Classes=self.classes)) else: reflist.insert(0, nodes.Text(' ')) ref.parent.insert(index, reflist) return footnote
Example #11
Source File: roles.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). set_classes(options) return [nodes.inline(rawtext, utils.unescape(text), **options)], []
Example #12
Source File: references.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def make_target_footnote(self, refuri, refs, notes): if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] else: # original footnote = nodes.footnote() footnote_id = self.document.set_id(footnote) # Use uppercase letters and a colon; they can't be # produced inside names by the parser. footnote_name = 'TARGET_NOTE: ' + footnote_id footnote['auto'] = 1 footnote['names'] = [footnote_name] footnote_paragraph = nodes.paragraph() footnote_paragraph += nodes.reference('', refuri, refuri=refuri) footnote += footnote_paragraph self.document.note_autofootnote(footnote) self.document.note_explicit_target(footnote, footnote) for ref in refs: if isinstance(ref, nodes.target): continue refnode = nodes.footnote_reference(refname=footnote_name, auto=1) refnode['classes'] += self.classes self.document.note_autofootnote_ref(refnode) self.document.note_footnote_ref(refnode) index = ref.parent.index(ref) + 1 reflist = [refnode] if not utils.get_trim_footnote_ref_space(self.document.settings): if self.classes: reflist.insert(0, nodes.inline(text=' ', Classes=self.classes)) else: reflist.insert(0, nodes.Text(' ')) ref.parent.insert(index, reflist) return footnote
Example #13
Source File: roles.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). set_classes(options) return [nodes.inline(rawtext, utils.unescape(text), **options)], []
Example #14
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 #15
Source File: references.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def make_target_footnote(self, refuri, refs, notes): if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] else: # original footnote = nodes.footnote() footnote_id = self.document.set_id(footnote) # Use uppercase letters and a colon; they can't be # produced inside names by the parser. footnote_name = 'TARGET_NOTE: ' + footnote_id footnote['auto'] = 1 footnote['names'] = [footnote_name] footnote_paragraph = nodes.paragraph() footnote_paragraph += nodes.reference('', refuri, refuri=refuri) footnote += footnote_paragraph self.document.note_autofootnote(footnote) self.document.note_explicit_target(footnote, footnote) for ref in refs: if isinstance(ref, nodes.target): continue refnode = nodes.footnote_reference(refname=footnote_name, auto=1) refnode['classes'] += self.classes self.document.note_autofootnote_ref(refnode) self.document.note_footnote_ref(refnode) index = ref.parent.index(ref) + 1 reflist = [refnode] if not utils.get_trim_footnote_ref_space(self.document.settings): if self.classes: reflist.insert(0, nodes.inline(text=' ', Classes=self.classes)) else: reflist.insert(0, nodes.Text(' ')) ref.parent.insert(index, reflist) return footnote
Example #16
Source File: numdoc_py3.py From typescript-guide with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def numdoc_role(name, rawtext, text, lineno, inliner, options={}, content=[]): """Role for making latex ref to the doc head.""" env = inliner.document.settings.env text = utils.unescape(text) has_explicit, title, target = split_explicit_title(text) pnode = nodes.inline(rawtext, title, classes=['xref','doc']) pnode['reftarget'] = target return [pnode], []
Example #17
Source File: citations.py From indra with BSD 2-Clause "Simplified" License | 5 votes |
def doi_reference_role(role, rawtext, text, lineno, inliner, options={}, content=[]): ref = doi_uri_pattern % text nodelist = [] nodelist.append(nodes.inline(text='doi:')) nodelist.append(nodes.reference(rawtext, utils.unescape(text), refuri=ref, **options)) return nodelist, []
Example #18
Source File: references.py From blackmamba with MIT License | 5 votes |
def make_target_footnote(self, refuri, refs, notes): if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] else: # original footnote = nodes.footnote() footnote_id = self.document.set_id(footnote) # Use uppercase letters and a colon; they can't be # produced inside names by the parser. footnote_name = 'TARGET_NOTE: ' + footnote_id footnote['auto'] = 1 footnote['names'] = [footnote_name] footnote_paragraph = nodes.paragraph() footnote_paragraph += nodes.reference('', refuri, refuri=refuri) footnote += footnote_paragraph self.document.note_autofootnote(footnote) self.document.note_explicit_target(footnote, footnote) for ref in refs: if isinstance(ref, nodes.target): continue refnode = nodes.footnote_reference(refname=footnote_name, auto=1) refnode['classes'] += self.classes self.document.note_autofootnote_ref(refnode) self.document.note_footnote_ref(refnode) index = ref.parent.index(ref) + 1 reflist = [refnode] if not utils.get_trim_footnote_ref_space(self.document.settings): if self.classes: reflist.insert(0, nodes.inline(text=' ', Classes=self.classes)) else: reflist.insert(0, nodes.Text(' ')) ref.parent.insert(index, reflist) return footnote
Example #19
Source File: roles.py From blackmamba with MIT License | 5 votes |
def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). set_classes(options) return [nodes.inline(rawtext, utils.unescape(text), **options)], []
Example #20
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 #21
Source File: references.py From aws-extender with MIT License | 5 votes |
def make_target_footnote(self, refuri, refs, notes): if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] else: # original footnote = nodes.footnote() footnote_id = self.document.set_id(footnote) # Use uppercase letters and a colon; they can't be # produced inside names by the parser. footnote_name = 'TARGET_NOTE: ' + footnote_id footnote['auto'] = 1 footnote['names'] = [footnote_name] footnote_paragraph = nodes.paragraph() footnote_paragraph += nodes.reference('', refuri, refuri=refuri) footnote += footnote_paragraph self.document.note_autofootnote(footnote) self.document.note_explicit_target(footnote, footnote) for ref in refs: if isinstance(ref, nodes.target): continue refnode = nodes.footnote_reference(refname=footnote_name, auto=1) refnode['classes'] += self.classes self.document.note_autofootnote_ref(refnode) self.document.note_footnote_ref(refnode) index = ref.parent.index(ref) + 1 reflist = [refnode] if not utils.get_trim_footnote_ref_space(self.document.settings): if self.classes: reflist.insert(0, nodes.inline(text=' ', Classes=self.classes)) else: reflist.insert(0, nodes.Text(' ')) ref.parent.insert(index, reflist) return footnote
Example #22
Source File: roles.py From aws-extender with MIT License | 5 votes |
def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). set_classes(options) return [nodes.inline(rawtext, utils.unescape(text), **options)], []
Example #23
Source File: docukatse.py From thonny with MIT License | 5 votes |
def reet_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). options["classes"] = "reet" return [nodes.inline(rawtext, docutils.utils.unescape(text), **options)], [] # register_generic_role('reet', nodes.literal)
Example #24
Source File: references.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def make_target_footnote(self, refuri, refs, notes): if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] else: # original footnote = nodes.footnote() footnote_id = self.document.set_id(footnote) # Use uppercase letters and a colon; they can't be # produced inside names by the parser. footnote_name = 'TARGET_NOTE: ' + footnote_id footnote['auto'] = 1 footnote['names'] = [footnote_name] footnote_paragraph = nodes.paragraph() footnote_paragraph += nodes.reference('', refuri, refuri=refuri) footnote += footnote_paragraph self.document.note_autofootnote(footnote) self.document.note_explicit_target(footnote, footnote) for ref in refs: if isinstance(ref, nodes.target): continue refnode = nodes.footnote_reference(refname=footnote_name, auto=1) refnode['classes'] += self.classes self.document.note_autofootnote_ref(refnode) self.document.note_footnote_ref(refnode) index = ref.parent.index(ref) + 1 reflist = [refnode] if not utils.get_trim_footnote_ref_space(self.document.settings): if self.classes: reflist.insert(0, nodes.inline(text=' ', Classes=self.classes)) else: reflist.insert(0, nodes.Text(' ')) ref.parent.insert(index, reflist) return footnote
Example #25
Source File: roles.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). set_classes(options) return [nodes.inline(rawtext, utils.unescape(text), **options)], []
Example #26
Source File: references.py From faces with GNU General Public License v2.0 | 5 votes |
def make_target_footnote(self, refuri, refs, notes): if refuri in notes: # duplicate? footnote = notes[refuri] assert len(footnote['names']) == 1 footnote_name = footnote['names'][0] else: # original footnote = nodes.footnote() footnote_id = self.document.set_id(footnote) # Use uppercase letters and a colon; they can't be # produced inside names by the parser. footnote_name = 'TARGET_NOTE: ' + footnote_id footnote['auto'] = 1 footnote['names'] = [footnote_name] footnote_paragraph = nodes.paragraph() footnote_paragraph += nodes.reference('', refuri, refuri=refuri) footnote += footnote_paragraph self.document.note_autofootnote(footnote) self.document.note_explicit_target(footnote, footnote) for ref in refs: if isinstance(ref, nodes.target): continue refnode = nodes.footnote_reference(refname=footnote_name, auto=1) refnode['classes'] += self.classes self.document.note_autofootnote_ref(refnode) self.document.note_footnote_ref(refnode) index = ref.parent.index(ref) + 1 reflist = [refnode] if not utils.get_trim_footnote_ref_space(self.document.settings): if self.classes: reflist.insert(0, nodes.inline(text=' ', Classes=self.classes)) else: reflist.insert(0, nodes.Text(' ')) ref.parent.insert(index, reflist) return footnote
Example #27
Source File: roles.py From faces with GNU General Public License v2.0 | 5 votes |
def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): """""" # Once nested inline markup is implemented, this and other methods should # recursively call inliner.nested_parse(). set_classes(options) return [nodes.inline(rawtext, utils.unescape(text), **options)], []
Example #28
Source File: roles.py From faces with GNU General Public License v2.0 | 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 #29
Source File: sphinxext.py From bioconda-utils with MIT License | 5 votes |
def make_field(self, types, domain, item, env=None): fieldname = nodes.field_name('', self.label) backref = addnodes.pending_xref( '', refdomain="conda", reftype='requiredby', refexplicit=False, reftarget=env.ref_context['conda:package'], refdoc=env.docname ) backref += nodes.inline('', '') fieldbody = nodes.field_body('', backref) return nodes.field('', fieldname, fieldbody)
Example #30
Source File: layout.py From sphinxcontrib-needs with MIT License | 5 votes |
def _parse(self, line): """ Parses a single line/string for inline rst statements, like strong, emphasis, literal, ... :param line: string to parse :return: nodes """ inline_parser = Inliner() inline_parser.init_customizations(self.doc_settings) result, message = inline_parser.parse(line, 0, self.doc_memo, self.dummy_doc) if message: raise SphinxNeedLayoutException(message) return result