Python docutils.nodes.paragraph() Examples
The following are 30
code examples of docutils.nodes.paragraph().
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: states.py From faces with GNU General Public License v2.0 | 6 votes |
def paragraph(self, lines, lineno): """ Return a list (paragraph & messages) & a boolean: literal_block next? """ data = '\n'.join(lines).rstrip() if re.search(r'(?<!\\)(\\\\)*::$', data): if len(data) == 2: return [], 1 elif data[-3] in ' \n': text = data[:-3].rstrip() else: text = data[:-1] literalnext = 1 else: text = data literalnext = 0 textnodes, messages = self.inline_text(text, lineno) p = nodes.paragraph(data, '', *textnodes) p.source, p.line = self.state_machine.get_source_and_line(lineno) return [p] + messages, literalnext
Example #2
Source File: ext.py From rucio with Apache License 2.0 | 6 votes |
def _format_subcommands(self, parser_info): assert 'children' in parser_info items = [] for subcmd in parser_info['children']: subcmd_items = [] if subcmd['help']: subcmd_items.append(nodes.paragraph(text=subcmd['help'])) else: subcmd_items.append(nodes.paragraph(text='Undocumented')) items.append( nodes.definition_list_item( '', nodes.term('', '', nodes.strong( text=subcmd['bare_usage'])), nodes.definition('', *subcmd_items))) return nodes.definition_list('', *items)
Example #3
Source File: ext.py From rucio with Apache License 2.0 | 6 votes |
def _format_positional_arguments(self, parser_info): assert 'args' in parser_info items = [] for arg in parser_info['args']: arg_items = [] if arg['help']: arg_items.append(nodes.paragraph(text=arg['help'])) elif 'choices' not in arg: arg_items.append(nodes.paragraph(text='Undocumented')) if 'choices' in arg: arg_items.append( nodes.paragraph( text='Possible choices: ' + ', '.join(arg['choices']))) items.append( nodes.option_list_item( '', nodes.option_group( '', nodes.option( '', nodes.option_string(text=arg['metavar']) ) ), nodes.description('', *arg_items))) return nodes.option_list('', *items)
Example #4
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_table(self, node): self.requirements['table'] = PreambleCmds.table if self.active_table.is_open(): self.table_stack.append(self.active_table) # nesting longtable does not work (e.g. 2007-04-18) self.active_table = Table(self,'tabular') # A longtable moves before \paragraph and \subparagraph # section titles if it immediately follows them: if (self.active_table._latex_type == 'longtable' and isinstance(node.parent, nodes.section) and node.parent.index(node) == 1 and self.d_class.section(self.section_level).find('paragraph') != -1): self.out.append('\\leavevmode') self.active_table.open() self.active_table.set_table_style(self.settings.table_style, node['classes']) if 'align' in node: self.active_table.set('align', node['align']) if self.active_table.borders == 'booktabs': self.requirements['booktabs'] = r'\usepackage{booktabs}' self.push_output_collector([])
Example #5
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def extract_extension_options(field_list, options_spec): """ Return a dictionary mapping extension option names to converted values. :Parameters: - `field_list`: A flat field list without field arguments, where each field body consists of a single paragraph only. - `options_spec`: Dictionary mapping known option names to a conversion function such as `int` or `float`. :Exceptions: - `KeyError` for unknown option names. - `ValueError` for invalid option values (raised by the conversion function). - `TypeError` for invalid option value types (raised by conversion function). - `DuplicateOptionError` for duplicate options. - `BadOptionError` for invalid fields. - `BadOptionDataError` for invalid option data (missing name, missing data, bad quotes, etc.). """ option_list = extract_options(field_list) option_dict = assemble_option_dict(option_list, options_spec) return option_dict
Example #6
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_paragraph(self, node): # insert blank line, unless # * the paragraph is first in a list item, # * follows a non-paragraph node in a compound, # * is in a table with auto-width columns index = node.parent.index(node) if (index == 0 and (isinstance(node.parent, nodes.list_item) or isinstance(node.parent, nodes.description))): pass elif (index > 0 and isinstance(node.parent, nodes.compound) and not isinstance(node.parent[index - 1], nodes.paragraph) and not isinstance(node.parent[index - 1], nodes.compound)): pass elif self.active_table.colwidths_auto: if index == 1: # second paragraph self.warn('LaTeX merges paragraphs in tables ' 'with auto-sized columns!', base_node=node) if index > 0: self.out.append('\n') else: self.out.append('\n') if node.get('ids'): self.out += self.ids_to_labels(node) + ['\n'] if node['classes']: self.visit_inline(node)
Example #7
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_footnote(self, node): try: backref = node['backrefs'][0] except IndexError: backref = node['ids'][0] # no backref, use self-ref instead if self.docutils_footnotes: self.fallbacks['footnotes'] = PreambleCmds.footnotes num = node[0].astext() if self.settings.footnote_references == 'brackets': num = '[%s]' % num self.out.append('%%\n\\DUfootnotetext{%s}{%s}{%s}{' % (node['ids'][0], backref, self.encode(num))) if node['ids'] == node['names']: self.out += self.ids_to_labels(node) # mask newline to prevent spurious whitespace if paragraph follows: if node[1:] and isinstance(node[1], nodes.paragraph): self.out.append('%') ## else: # TODO: "real" LaTeX \footnote{}s
Example #8
Source File: states.py From faces with GNU General Public License v2.0 | 6 votes |
def paragraph(self, lines, lineno): """ Return a list (paragraph & messages) & a boolean: literal_block next? """ data = '\n'.join(lines).rstrip() if re.search(r'(?<!\\)(\\\\)*::$', data): if len(data) == 2: return [], 1 elif data[-3] in ' \n': text = data[:-3].rstrip() else: text = data[:-1] literalnext = 1 else: text = data literalnext = 0 textnodes, messages = self.inline_text(text, lineno) p = nodes.paragraph(data, '', *textnodes) p.source, p.line = self.state_machine.get_source_and_line(lineno) return [p] + messages, literalnext
Example #9
Source File: sphinx_cfg_options.py From tenpy with GNU General Public License v3.0 | 6 votes |
def create_option_reference(self, option, config, context): par = nodes.paragraph() innernode = addnodes.literal_strong(option.dispname, option.dispname) par += self.make_refnode(option.docname, option.anchor, innernode) if option.config != config: par += nodes.Text(" (from ") par += self._make_config_xref(option.config) par += nodes.Text(")") if option.context is not None: opt_context = option.context if opt_context.startswith(context): opt_context = opt_context[len(context):] if opt_context: par += nodes.Text(" in ") par += addnodes.literal_emphasis(option.context, option.context) return par
Example #10
Source File: _html_base.py From faces with GNU General Public License v2.0 | 6 votes |
def depart_organization(self, node): self.depart_docinfo_item() # Do not omit <p> tags # -------------------- # # The HTML4CSS1 writer does this to "produce # visually compact lists (less vertical whitespace)". This writer # relies on CSS rules for"visual compactness". # # * In XHTML 1.1, e.g. a <blockquote> element may not contain # character data, so you cannot drop the <p> tags. # * Keeping simple paragraphs in the field_body enables a CSS # rule to start the field-body on a new line if the label is too long # * it makes the code simpler. # # TODO: omit paragraph tags in simple table cells?
Example #11
Source File: support_matrix.py From designate with Apache License 2.0 | 6 votes |
def _build_backend_detail(self, matrix, content): detailstitle = nodes.subtitle(text="Backend Details") content.append(detailstitle) content.append(nodes.paragraph()) for key in six.iterkeys(matrix.backends): content.append( nodes.subtitle(text=matrix.backends[key].title)) content.append( self._build_backend_detail_table( matrix.backends[key], matrix)) content.append(nodes.paragraph()) return content
Example #12
Source File: speciescatalog.py From stdpopsim with GNU General Public License v3.0 | 6 votes |
def models_table(self, species): table = nodes.table() tgroup = nodes.tgroup(cols=2) for _ in range(2): colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) table += tgroup thead = nodes.thead() tgroup += thead row = nodes.row() entry = nodes.entry() entry += nodes.paragraph(text="ID") row += entry entry = nodes.entry() entry += nodes.paragraph(text="Description") row += entry thead.append(row) rows = [] for model in species.demographic_models: row = nodes.row() rows.append(row) mid = self.get_demographic_model_id(species, model) entry = nodes.entry() para = nodes.paragraph() entry += para para += nodes.reference(internal=True, refid=mid, text=model.id) row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.description) row += entry tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
Example #13
Source File: states.py From faces with GNU General Public License v2.0 | 6 votes |
def text(self, match, context, next_state): """Paragraph.""" startline = self.state_machine.abs_line_number() - 1 msg = None try: block = self.state_machine.get_text_block(flush_left=True) except statemachine.UnexpectedIndentationError as err: block, src, srcline = err.args msg = self.reporter.error('Unexpected indentation.', source=src, line=srcline) lines = context + list(block) paragraph, literalnext = self.paragraph(lines, startline) self.parent += paragraph self.parent += msg if literalnext: try: self.state_machine.next_line() except EOFError: pass self.parent += self.literal_block() return [], next_state, []
Example #14
Source File: speciescatalog.py From stdpopsim with GNU General Public License v3.0 | 6 votes |
def make_field_list(self, data): field_list = nodes.field_list() for name, text, citations in data: field = nodes.field() field_name = nodes.field_name(text=name) field_body = nodes.field_body() para = nodes.paragraph(text=text) if citations is not None and len(citations) > 0: para += nodes.Text(" (") for i, citation in enumerate(citations): text = f"{citation.author}, {citation.year}" para += nodes.reference( internal=False, refuri=citation.doi, text=text) if i != len(citations)-1: para += nodes.Text("; ") para += nodes.Text(")") field_body += para field += field_name field += field_body field_list += field return field_list
Example #15
Source File: sphinxext.py From bioconda-utils with MIT License | 6 votes |
def resolve_required_by_xrefs(app, env, node, contnode): """Now that all recipes and packages have been parsed, we are called here for each ``pending_xref`` node that sphinx has not been able to resolve. We handle specifically the ``requiredby`` reftype created by the `RequiredByField` fieldtype allowed in ``conda:package::`` directives, where we replace the ``pending_ref`` node with a bullet list of reference nodes pointing to the package pages that "depended" on the package. """ if node['reftype'] == 'requiredby' and node['refdomain'] == 'conda': target = node['reftarget'] docname = node['refdoc'] backrefs = env.domains['conda'].data['backrefs'].get(target, set()) listnode = nodes.bullet_list() for back_docname, back_target in backrefs: par = nodes.paragraph() name_node = addnodes.literal_strong(back_target, back_target, classes=['xref', 'backref']) refnode = make_refnode(app.builder, docname, back_docname, back_target, name_node) refnode.set_class('conda-package') par += refnode listnode += nodes.list_item('', par) return listnode
Example #16
Source File: sphinxext.py From bioconda-utils with MIT License | 6 votes |
def make_field(self, types, domain, items, env=None): fieldname = nodes.field_name('', self.label) listnode = self.list_type() for fieldarg, content in items: par = nodes.paragraph() par.extend(self.make_xrefs(self.rolename, domain, fieldarg, addnodes.literal_strong, env=env)) if content and content[0].astext(): par += nodes.Text(' ') par += content listnode += nodes.list_item('', par) source = env.ref_context['conda:package'] backrefs = env.domains['conda'].data['backrefs'].setdefault(fieldarg, set()) backrefs.add((env.docname, source)) fieldbody = nodes.field_body('', listnode) fieldbody.set_class('field-list-wrapped') return nodes.field('', fieldname, fieldbody)
Example #17
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def extract_extension_options(field_list, options_spec): """ Return a dictionary mapping extension option names to converted values. :Parameters: - `field_list`: A flat field list without field arguments, where each field body consists of a single paragraph only. - `options_spec`: Dictionary mapping known option names to a conversion function such as `int` or `float`. :Exceptions: - `KeyError` for unknown option names. - `ValueError` for invalid option values (raised by the conversion function). - `TypeError` for invalid option value types (raised by conversion function). - `DuplicateOptionError` for duplicate options. - `BadOptionError` for invalid fields. - `BadOptionDataError` for invalid option data (missing name, missing data, bad quotes, etc.). """ option_list = extract_options(field_list) option_dict = assemble_option_dict(option_list, options_spec) return option_dict
Example #18
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_list_item(self, node): children = [] for child in node.children: if not isinstance(child, nodes.Invisible): children.append(child) if (children and isinstance(children[0], nodes.paragraph) and (isinstance(children[-1], nodes.bullet_list) or isinstance(children[-1], nodes.enumerated_list))): children.pop() if len(children) <= 1: return else: raise nodes.NodeFound # def visit_bullet_list(self, node): # pass # def visit_enumerated_list(self, node): # pass # def visit_paragraph(self, node): # raise nodes.SkipNode
Example #19
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
def __init__(self, document_class, with_part=False): self.document_class = document_class self._with_part = with_part self.sections = ['section', 'subsection', 'subsubsection', 'paragraph', 'subparagraph'] if self.document_class in ('book', 'memoir', 'report', 'scrbook', 'scrreprt'): self.sections.insert(0, 'chapter') if self._with_part: self.sections.insert(0, 'part')
Example #20
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
def visit_field_list(self, node): self.context.append((self.compact_field_list, self.compact_p)) self.compact_p = None if 'compact' in node['classes']: self.compact_field_list = True elif (self.settings.compact_field_lists and 'open' not in node['classes']): self.compact_field_list = True if self.compact_field_list: for field in node: field_body = field[-1] assert isinstance(field_body, nodes.field_body) children = [n for n in field_body if not isinstance(n, nodes.Invisible)] if not (len(children) == 0 or len(children) == 1 and isinstance(children[0], (nodes.paragraph, nodes.line_block))): self.compact_field_list = False break self.body.append(self.starttag(node, 'table', frame='void', rules='none', CLASS='docutils field-list')) self.body.append('<col class="field-name" />\n' '<col class="field-body" />\n' '<tbody valign="top">\n')
Example #21
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
def should_be_compact_paragraph(self, node): """ Determine if the <p> tags around paragraph ``node`` can be omitted. """ if (isinstance(node.parent, nodes.document) or isinstance(node.parent, nodes.compound)): # Never compact paragraphs in document or compound. return False for key, value in node.attlist(): if (node.is_not_default(key) and not (key == 'classes' and value in ([], ['first'], ['last'], ['first', 'last']))): # Attribute which needs to survive. return False first = isinstance(node.parent[0], nodes.label) # skip label for child in node.parent.children[first:]: # only first paragraph can be compact if isinstance(child, nodes.Invisible): continue if child is node: break return False parent_length = len([n for n in node.parent if not isinstance( n, (nodes.Invisible, nodes.label))]) if ( self.compact_simple or self.compact_field_list or self.compact_p and parent_length == 1): return True return False
Example #22
Source File: states.py From faces with GNU General Public License v2.0 | 5 votes |
def parse_field_body(self, indented, offset, node): """Override `Body.parse_field_body` for simpler parsing.""" lines = [] for line in list(indented) + ['']: if line.strip(): lines.append(line) elif lines: text = '\n'.join(lines) node += nodes.paragraph(text, text) lines = []
Example #23
Source File: references.py From faces with GNU General Public License v2.0 | 5 votes |
def resolve_reference_ids(self, target): """ Given:: <paragraph> <reference refname="direct internal"> direct internal <target id="id1" name="direct internal"> The "refname" attribute is replaced by "refid" linking to the target's "id":: <paragraph> <reference refid="id1"> direct internal <target id="id1" name="direct internal"> """ for name in target['names']: refid = self.document.nameids.get(name) reflist = self.document.refnames.get(name, []) if reflist: target.note_referenced_by(name=name) for ref in reflist: if ref.resolved: continue if refid: del ref['refname'] ref['refid'] = refid ref.resolved = 1
Example #24
Source File: parts.py From faces with GNU General Public License v2.0 | 5 votes |
def build_contents(self, node, level=0): level += 1 sections = [sect for sect in node if isinstance(sect, nodes.section)] entries = [] autonum = 0 depth = self.startnode.details.get('depth', sys.maxint) for section in sections: title = section[0] auto = title.get('auto') # May be set by SectNum. entrytext = self.copy_and_filter(title) reference = nodes.reference('', '', refid=section['ids'][0], *entrytext) ref_id = self.document.set_id(reference) entry = nodes.paragraph('', '', reference) item = nodes.list_item('', entry) if ( self.backlinks in ('entry', 'top') and title.next_node(nodes.reference) is None): if self.backlinks == 'entry': title['refid'] = ref_id elif self.backlinks == 'top': title['refid'] = self.toc_id if level < depth: subsects = self.build_contents(section, level) item += subsects entries.append(item) if entries: contents = nodes.bullet_list('', *entries) if auto: contents['classes'].append('auto-toc') return contents else: return []
Example #25
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 #26
Source File: frontmatter.py From faces with GNU General Public License v2.0 | 5 votes |
def check_compound_biblio_field(self, field, name): if len(field[-1]) > 1: field[-1] += self.document.reporter.warning( 'Cannot extract compound bibliographic field "%s".' % name, base_node=field) return None if not isinstance(field[-1][0], nodes.paragraph): field[-1] += self.document.reporter.warning( 'Cannot extract bibliographic field "%s" containing ' 'anything other than a single paragraph.' % name, base_node=field) return None return 1
Example #27
Source File: pipext.py From FuYiSpider with Apache License 2.0 | 5 votes |
def run(self): node = nodes.paragraph() node.document = self.state.document self.view_list = ViewList() self.process_options() self.state.nested_parse(self.view_list, 0, node) return [node]
Example #28
Source File: custom_directives.py From qml with Apache License 2.0 | 5 votes |
def run(self): ytid = self.arguments[0] description = [i if i != "" else "<br><br>" for i in self.content] thumbnail_rst = YOUTUBE_TEMPLATE.format(id=ytid, title=self.options["title"], author=self.options["author"], description=" ".join(description)) thumbnail = StringList(thumbnail_rst.split('\n')) thumb = nodes.paragraph() self.state.nested_parse(thumbnail, self.content_offset, thumb) return [thumb]
Example #29
Source File: sphinxext.py From bioconda-utils with MIT License | 5 votes |
def run(self): #self.env: BuildEnvironment = self.state.document.settings.env return [nodes.paragraph('')]
Example #30
Source File: pipext.py From FuYiSpider with Apache License 2.0 | 5 votes |
def run(self): node = nodes.paragraph() node.document = self.state.document desc = ViewList() description = dedent(commands[self.arguments[0]].__doc__) for line in description.split('\n'): desc.append(line, "") self.state.nested_parse(desc, 0, node) return [node]