Python docutils.nodes.title() Examples
The following are 30
code examples of docutils.nodes.title().
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 line(self, match, context, next_state): """Section title overline or transition marker.""" if self.state_machine.match_titles: return [match.string], 'Line', [] elif match.string.strip() == '::': raise statemachine.TransitionCorrection('text') elif len(match.string.strip()) < 4: msg = self.reporter.info( 'Unexpected possible title overline or transition.\n' "Treating it as ordinary text because it's so short.", line=self.state_machine.abs_line_number()) self.parent += msg raise statemachine.TransitionCorrection('text') else: blocktext = self.state_machine.line msg = self.reporter.severe( 'Unexpected section title or transition.', nodes.literal_block(blocktext, blocktext), line=self.state_machine.abs_line_number()) self.parent += msg return [], next_state, []
Example #2
Source File: tables.py From faces with GNU General Public License v2.0 | 6 votes |
def run(self): if not self.content: error = self.state_machine.reporter.error( 'The "%s" directive is empty; content required.' % self.name, nodes.literal_block(self.block_text, self.block_text), line=self.lineno) return [error] title, messages = self.make_title() node = nodes.Element() # anonymous container for parsing self.state.nested_parse(self.content, self.content_offset, node) try: num_cols, widths, col_widths = self.check_list_content(node) table_data = [[item.children for item in row_list[0]] for row_list in node[0]] header_rows = self.options.get('header-rows', 0) stub_columns = self.options.get('stub-columns', 0) self.check_table_dimensions(table_data, header_rows, stub_columns) except SystemMessagePropagation, detail: return [detail.args[0]]
Example #3
Source File: body.py From faces with GNU General Public License v2.0 | 6 votes |
def run(self): if not (self.state_machine.match_titles or isinstance(self.state_machine.node, nodes.sidebar)): raise self.error('The "%s" directive may not be used within ' 'topics or body elements.' % self.name) self.assert_has_content() title_text = self.arguments[0] textnodes, messages = self.state.inline_text(title_text, self.lineno) titles = [nodes.title(title_text, '', *textnodes)] # Sidebar uses this code. if 'subtitle' in self.options: textnodes, more_messages = self.state.inline_text( self.options['subtitle'], self.lineno) titles.append(nodes.subtitle(self.options['subtitle'], '', *textnodes)) messages.extend(more_messages) text = '\n'.join(self.content) node = self.node_class(text, *(titles + messages)) node['classes'] += self.options.get('class', []) self.add_name(node) if text: self.state.nested_parse(self.content, self.content_offset, node) return [node]
Example #4
Source File: admonitions.py From faces with GNU General Public License v2.0 | 6 votes |
def run(self): set_classes(self.options) self.assert_has_content() text = '\n'.join(self.content) admonition_node = self.node_class(text, **self.options) self.add_name(admonition_node) if self.node_class is nodes.admonition: title_text = self.arguments[0] textnodes, messages = self.state.inline_text(title_text, self.lineno) title = nodes.title(title_text, '', *textnodes) title.source, title.line = ( self.state_machine.get_source_and_line(self.lineno)) admonition_node += title admonition_node += messages if not 'classes' in self.options: admonition_node['classes'] += ['admonition-' + nodes.make_id(title_text)] self.state.nested_parse(self.content, self.content_offset, admonition_node) return [admonition_node]
Example #5
Source File: states.py From faces with GNU General Public License v2.0 | 6 votes |
def line(self, match, context, next_state): """Section title overline or transition marker.""" if self.state_machine.match_titles: return [match.string], 'Line', [] elif match.string.strip() == '::': raise statemachine.TransitionCorrection('text') elif len(match.string.strip()) < 4: msg = self.reporter.info( 'Unexpected possible title overline or transition.\n' "Treating it as ordinary text because it's so short.", line=self.state_machine.abs_line_number()) self.parent += msg raise statemachine.TransitionCorrection('text') else: blocktext = self.state_machine.line msg = self.reporter.severe( 'Unexpected section title or transition.', nodes.literal_block(blocktext, blocktext), line=self.state_machine.abs_line_number()) self.parent += msg return [], next_state, []
Example #6
Source File: states.py From faces with GNU General Public License v2.0 | 6 votes |
def new_subsection(self, title, lineno, messages): """Append new subsection to document tree. On return, check level.""" memo = self.memo mylevel = memo.section_level memo.section_level += 1 section_node = nodes.section() self.parent += section_node textnodes, title_messages = self.inline_text(title, lineno) titlenode = nodes.title(title, '', *textnodes) name = normalize_name(titlenode.astext()) section_node['names'].append(name) section_node += titlenode section_node += messages section_node += title_messages self.document.note_implicit_target(section_node, section_node) offset = self.state_machine.line_offset + 1 absoffset = self.state_machine.abs_line_offset() + 1 newabsoffset = self.nested_parse( self.state_machine.input_lines[offset:], input_offset=absoffset, node=section_node, match_titles=True) self.goto_line(newabsoffset) if memo.section_level <= mylevel: # can't handle next section? raise EOFError # bubble up to supersection # reset section_level; next pass will detect it properly memo.section_level = mylevel
Example #7
Source File: eql.py From edgedb with Apache License 2.0 | 6 votes |
def make_xref(self, rolename, domain, target, innernode=d_nodes.emphasis, contnode=None, env=None): if not rolename: return contnode or innernode(target, target) title = target if domain == 'eql' and rolename == 'type': target = EQLTypeXRef.filter_target(target) if target in EQLTypedField.ignored_types: return d_nodes.Text(title) refnode = s_nodes.pending_xref('', refdomain=domain, refexplicit=title != target, reftype=rolename, reftarget=target) refnode += contnode or innernode(title, title) if env: env.domains[domain].process_field_xref(refnode) refnode['eql-auto-link'] = True return refnode
Example #8
Source File: ext.py From rucio with Apache License 2.0 | 6 votes |
def ensureUniqueIDs(items): """ If action groups are repeated, then links in the table of contents will just go to the first of the repeats. This may not be desirable, particularly in the case of subcommands where the option groups have different members. This function updates the title IDs by adding _repeatX, where X is a number so that the links are then unique. """ s = set() for item in items: for n in item.traverse(descend=True, siblings=True, ascend=False): if isinstance(n, nodes.section): ids = n['ids'] for idx, id in enumerate(ids): if id not in s: s.add(id) else: i = 1 while "{}_repeat{}".format(id, i) in s: i += 1 ids[idx] = "{}_repeat{}".format(id, i) s.add(ids[idx]) n['ids'] = ids
Example #9
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_system_message(self, node): self.requirements['color'] = PreambleCmds.color self.fallbacks['title'] = PreambleCmds.title node['classes'] = ['system-message'] self.visit_admonition(node) self.out.append('\\DUtitle[system-message]{system-message}\n') self.append_hypertargets(node) try: line = ', line~%s' % node['line'] except KeyError: line = '' self.out.append('\n\n{\color{red}%s/%s} in \\texttt{%s}%s\n' % (node['type'], node['level'], self.encode(node['source']), line)) if len(node['backrefs']) == 1: self.out.append('\n\\hyperlink{%s}{' % node['backrefs'][0]) self.context.append('}') else: backrefs = ['\\hyperlink{%s}{%d}' % (href, i+1) for (i, href) in enumerate(node['backrefs'])] self.context.append('backrefs: ' + ' '.join(backrefs))
Example #10
Source File: eql.py From edgedb with Apache License 2.0 | 5 votes |
def process_link(self, env, refnode, has_explicit_title, title, target): new_target = self.filter_target(target) if not has_explicit_title: title = target.replace('-', ' ') return super().process_link( env, refnode, has_explicit_title, title, new_target)
Example #11
Source File: eql.py From edgedb with Apache License 2.0 | 5 votes |
def process_link(self, env, refnode, has_explicit_title, title, target): if not has_explicit_title: title += '()' return super().process_link( env, refnode, has_explicit_title, title, target)
Example #12
Source File: peps.py From deepWordBug with Apache License 2.0 | 5 votes |
def apply(self): language = languages.get_language(self.document.settings.language_code, self.document.reporter) name = language.labels['contents'] title = nodes.title('', name) topic = nodes.topic('', title, classes=['contents']) name = nodes.fully_normalize_name(name) if not self.document.has_name(name): topic['names'].append(name) self.document.note_implicit_target(topic) pending = nodes.pending(parts.Contents) topic += pending self.document.insert(1, topic) self.document.note_pending(pending)
Example #13
Source File: sphinxext.py From bioconda-utils with MIT License | 5 votes |
def run(self): if not hasattr(self.env, 'bioconda_lint_checks'): self.env.bioconda_lint_checks = {str(check): check for check in get_checks()} # gather data check_name = self.arguments[0] if check_name not in self.env.bioconda_lint_checks: self.error("Duplicate lint description") check = self.env.bioconda_lint_checks.pop(check_name) _, lineno = inspect.getsourcelines(check) lineno += 1 fname = inspect.getfile(check) doclines = inspect.getdoc(check).splitlines() docline_src = [(fname, i) for i in range(lineno, lineno+len(doclines))] lines = StringList(doclines, items=docline_src) # create a new section with title section = nodes.section(ids=[nodes.make_id(check_name)]) title_text = f'":py:class:`{check_name}`"' title_nodes, messages = self.state.inline_text(title_text, self.lineno) title = nodes.title(check_name, '', *title_nodes) section += title admonition = nodes.admonition() title_text = doclines[0].rstrip('.') title_nodes, messages = self.state.inline_text(title_text, lineno) title = nodes.title(title_text, '', *title_nodes) admonition += title admonition += messages self.state.nested_parse(lines[1:], 0, admonition) section += admonition # add remaining content of directive par = nodes.paragraph() self.state.nested_parse(self.content, self.content_offset, par) section += par return [section]
Example #14
Source File: question.py From docs with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run(self): target_id = 'question-%d' % self.env.new_serialno('question') target_node = nodes.target('', '', ids=[target_id]) question_node = QuestionAdmonition(self.content) question_node += nodes.title(text='Question') question_node['classes'] += ['question'] self.state.nested_parse(self.content, self.content_offset, question_node) return [target_node, question_node]
Example #15
Source File: checkpoint.py From docs with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run(self): target_id = 'checkpoint-%d' % self.env.new_serialno('checkpoint') target_node = nodes.target('', '', ids=[target_id]) checkpoint_node = CheckpointAdmonition(self.content) checkpoint_node += nodes.title(text='Checkpoint') checkpoint_node['classes'] += ['checkpoint'] self.state.nested_parse(self.content, self.content_offset, checkpoint_node) return [target_node, checkpoint_node]
Example #16
Source File: states.py From faces with GNU General Public License v2.0 | 5 votes |
def check_subsection(self, source, style, lineno): """ Check for a valid subsection header. Return 1 (true) or None (false). When a new section is reached that isn't a subsection of the current section, back up the line count (use ``previous_line(-x)``), then ``raise EOFError``. The current StateMachine will finish, then the calling StateMachine can re-examine the title. This will work its way back up the calling chain until the correct section level isreached. @@@ Alternative: Evaluate the title, store the title info & level, and back up the chain until that level is reached. Store in memo? Or return in results? :Exception: `EOFError` when a sibling or supersection encountered. """ memo = self.memo title_styles = memo.title_styles mylevel = memo.section_level try: # check for existing title style level = title_styles.index(style) + 1 except ValueError: # new title style if len(title_styles) == memo.section_level: # new subsection title_styles.append(style) return 1 else: # not at lowest level self.parent += self.title_inconsistent(source, lineno) return None if level <= mylevel: # sibling or supersection memo.section_level = level # bubble up to parent section if len(style) == 2: memo.section_bubble_up_kludge = True # back up 2 lines for underline title, 3 for overline title self.state_machine.previous_line(len(style) + 1) raise EOFError # let parent section re-evaluate if level == mylevel + 1: # immediate subsection return 1 else: # invalid subsection self.parent += self.title_inconsistent(source, lineno) return None
Example #17
Source File: states.py From faces with GNU General Public License v2.0 | 5 votes |
def underline(self, match, context, next_state): """Section title.""" lineno = self.state_machine.abs_line_number() title = context[0].rstrip() underline = match.string.rstrip() source = title + '\n' + underline messages = [] if column_width(title) > len(underline): if len(underline) < 4: if self.state_machine.match_titles: msg = self.reporter.info( 'Possible title underline, too short for the title.\n' "Treating it as ordinary text because it's so short.", line=lineno) self.parent += msg raise statemachine.TransitionCorrection('text') else: blocktext = context[0] + '\n' + self.state_machine.line msg = self.reporter.warning('Title underline too short.', nodes.literal_block(blocktext, blocktext), line=lineno) messages.append(msg) if not self.state_machine.match_titles: blocktext = context[0] + '\n' + self.state_machine.line # We need get_source_and_line() here to report correctly src, srcline = self.state_machine.get_source_and_line() # TODO: why is abs_line_number() == srcline+1 # if the error is in a table (try with test_tables.py)? # print "get_source_and_line", srcline # print "abs_line_number", self.state_machine.abs_line_number() msg = self.reporter.severe('Unexpected section title.', nodes.literal_block(blocktext, blocktext), source=src, line=srcline) self.parent += messages self.parent += msg return [], next_state, [] style = underline[0] context[:] = [] self.section(title, source, style, lineno - 1, messages) return [], next_state, []
Example #18
Source File: qiime1.py From docs with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run(self): target_id = 'qiime1users-%d' % self.env.new_serialno('qiime1users') target_node = nodes.target('', '', ids=[target_id]) qiime1user_node = QIIME1UsersAdmonition(self.content) qiime1user_node += nodes.title(text='QIIME 1 Users') qiime1user_node['classes'] += ['qiime1'] self.state.nested_parse(self.content, self.content_offset, qiime1user_node) return [target_node, qiime1user_node]
Example #19
Source File: sphinxext.py From bioconda-utils with MIT License | 5 votes |
def handle_signature(self, sig: str, signode: addnodes.desc) -> str: """Transform signature into RST nodes""" signode += addnodes.desc_annotation(self.typename, self.typename + " ") signode += addnodes.desc_name(sig, sig) if 'badges' in self.options: badges = addnodes.desc_annotation() badges['classes'] += ['badges'] content = StringList([self.options['badges']]) self.state.nested_parse(content, 0, badges) signode += badges if 'replaces_section_title' in self.options: section = self.state.parent if isinstance(section, nodes.section): title = section[-1] if isinstance(title, nodes.title): section.remove(title) else: signode += self.state.document.reporter.warning( "%s:%s:: must follow section directly to replace section title" % (self.domain, self.objtype), line = self.lineno ) else: signode += self.state.document.reporter.warning( "%s:%s:: must be in section to replace section title" % (self.domain, self.objtype), line = self.lineno ) return sig
Example #20
Source File: peps.py From faces with GNU General Public License v2.0 | 5 votes |
def apply(self): language = languages.get_language(self.document.settings.language_code, self.document.reporter) name = language.labels['contents'] title = nodes.title('', name) topic = nodes.topic('', title, classes=['contents']) name = nodes.fully_normalize_name(name) if not self.document.has_name(name): topic['names'].append(name) self.document.note_implicit_target(topic) pending = nodes.pending(parts.Contents) topic += pending self.document.insert(1, topic) self.document.note_pending(pending)
Example #21
Source File: tables.py From faces with GNU General Public License v2.0 | 5 votes |
def run(self): if not self.content: warning = self.state_machine.reporter.warning( 'Content block expected for the "%s" directive; none found.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [warning] title, messages = self.make_title() node = nodes.Element() # anonymous container for parsing self.state.nested_parse(self.content, self.content_offset, node) if len(node) != 1 or not isinstance(node[0], nodes.table): error = self.state_machine.reporter.error( 'Error parsing content block for the "%s" directive: exactly ' 'one table expected.' % self.name, nodes.literal_block( self.block_text, self.block_text), line=self.lineno) return [error] table_node = node[0] table_node['classes'] += self.options.get('class', []) if 'align' in self.options: table_node['align'] = self.options.get('align') tgroup = table_node[0] if type(self.widths) == list: colspecs = [child for child in tgroup.children if child.tagname == 'colspec'] for colspec, col_width in zip(colspecs, self.widths): colspec['colwidth'] = col_width # @@@ the colwidths argument for <tgroup> is not part of the # XML Exchange Table spec (https://www.oasis-open.org/specs/tm9901.htm) # and hence violates the docutils.dtd. if self.widths == 'auto': table_node['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table_node['classes'] += ['colwidths-given'] self.add_name(table_node) if title: table_node.insert(0, title) return [table_node] + messages
Example #22
Source File: tables.py From faces with GNU General Public License v2.0 | 5 votes |
def make_title(self): if self.arguments: title_text = self.arguments[0] text_nodes, messages = self.state.inline_text(title_text, self.lineno) title = nodes.title(title_text, '', *text_nodes) else: title = None messages = [] return title, messages
Example #23
Source File: universal.py From faces with GNU General Public License v2.0 | 5 votes |
def apply(self): unfiltered = self.document.transform_messages threshold = self.document.reporter.report_level messages = [] for msg in unfiltered: if msg['level'] >= threshold and not msg.parent: messages.append(msg) if messages: section = nodes.section(classes=['system-messages']) # @@@ get this from the language module? section += nodes.title('', 'Docutils System Messages') section += messages self.document.transform_messages[:] = [] self.document += section
Example #24
Source File: writer_aux.py From faces with GNU General Public License v2.0 | 5 votes |
def apply(self): language = languages.get_language(self.document.settings.language_code, self.document.reporter) for node in self.document.traverse(nodes.Admonition): node_name = node.__class__.__name__ # Set class, so that we know what node this admonition came from. node['classes'].append(node_name) if not isinstance(node, nodes.admonition): # Specific admonition. Transform into a generic admonition. admonition = nodes.admonition(node.rawsource, *node.children, **node.attributes) title = nodes.title('', language.labels[node_name]) admonition.insert(0, title) node.replace_self(admonition)
Example #25
Source File: frontmatter.py From faces with GNU General Public License v2.0 | 5 votes |
def apply(self): if getattr(self.document.settings, 'doctitle_xform', 1): # promote_(sub)title defined in TitlePromoter base class. if self.promote_title(self.document): # If a title has been promoted, also try to promote a # subtitle. self.promote_subtitle(self.document) # Set document['title']. self.set_metadata()
Example #26
Source File: frontmatter.py From faces with GNU General Public License v2.0 | 5 votes |
def set_metadata(self): """ Set document['title'] metadata title from the following sources, listed in order of priority: * Existing document['title'] attribute. * "title" setting. * Document title node (as promoted by promote_title). """ if not self.document.hasattr('title'): if self.document.settings.title is not None: self.document['title'] = self.document.settings.title elif len(self.document) and isinstance(self.document[0], nodes.title): self.document['title'] = self.document[0].astext()
Example #27
Source File: peps.py From deepWordBug with Apache License 2.0 | 5 votes |
def apply(self): doc = self.document i = len(doc) - 1 refsect = copyright = None while i >= 0 and isinstance(doc[i], nodes.section): title_words = doc[i][0].astext().lower().split() if 'references' in title_words: refsect = doc[i] break elif 'copyright' in title_words: copyright = i i -= 1 if not refsect: refsect = nodes.section() refsect += nodes.title('', 'References') doc.set_id(refsect) if copyright: # Put the new "References" section before "Copyright": doc.insert(copyright, refsect) else: # Put the new "References" section at end of doc: doc.append(refsect) pending = nodes.pending(references.TargetNotes) refsect.append(pending) self.document.note_pending(pending, 0) pending = nodes.pending(misc.CallBack, details={'callback': self.cleanup_callback}) refsect.append(pending) self.document.note_pending(pending, 1)
Example #28
Source File: peps.py From deepWordBug with Apache License 2.0 | 5 votes |
def cleanup_callback(self, pending): """ Remove an empty "References" section. Called after the `references.TargetNotes` transform is complete. """ if len(pending.parent) == 2: # <title> and <pending> pending.parent.parent.remove(pending.parent)
Example #29
Source File: peps.py From faces with GNU General Public License v2.0 | 5 votes |
def apply(self): doc = self.document i = len(doc) - 1 refsect = copyright = None while i >= 0 and isinstance(doc[i], nodes.section): title_words = doc[i][0].astext().lower().split() if 'references' in title_words: refsect = doc[i] break elif 'copyright' in title_words: copyright = i i -= 1 if not refsect: refsect = nodes.section() refsect += nodes.title('', 'References') doc.set_id(refsect) if copyright: # Put the new "References" section before "Copyright": doc.insert(copyright, refsect) else: # Put the new "References" section at end of doc: doc.append(refsect) pending = nodes.pending(references.TargetNotes) refsect.append(pending) self.document.note_pending(pending, 0) pending = nodes.pending(misc.CallBack, details={'callback': self.cleanup_callback}) refsect.append(pending) self.document.note_pending(pending, 1)
Example #30
Source File: frontmatter.py From deepWordBug with Apache License 2.0 | 5 votes |
def set_metadata(self): """ Set document['title'] metadata title from the following sources, listed in order of priority: * Existing document['title'] attribute. * "title" setting. * Document title node (as promoted by promote_title). """ if not self.document.hasattr('title'): if self.document.settings.title is not None: self.document['title'] = self.document.settings.title elif len(self.document) and isinstance(self.document[0], nodes.title): self.document['title'] = self.document[0].astext()