def visit_docinfo_item(self, node, name): if name == 'author': self._docinfo[name].append(node.astext()) else: self._docinfo[name] = node.astext() self._docinfo_keys.append(name) raise nodes.SkipNode()
def visit_label(self, node): # footnote and citation if (isinstance(node.parent, nodes.footnote) or isinstance(node.parent, nodes.citation)): raise nodes.SkipNode() self.document.reporter.warning('"unsupported "label"', base_node=node) self.body.append('[')
def visit_desc_parameter(self, node): if not self.first_param: self.add_text(', ') else: self.first_param = 0 self.add_text(node.astext()) raise nodes.SkipNode()
def visit_image(self, node): self.document.reporter.warning('"image" not supported', base_node=node) text = [] if 'alt' in node.attributes: text.append(node.attributes['alt']) if 'uri' in node.attributes: text.append(node.attributes['uri']) self.body.append('[image: %s]\n' % ('/'.join(text))) raise nodes.SkipNode()
def visit_productionlist(self, node): self.new_state() names = [] for production in node: names.append(production['tokenname']) maxlen = max(len(name) for name in names) for production in node: if production['tokenname']: self.add_text(production['tokenname'].ljust(maxlen) + ' ::=') lastname = production['tokenname'] else: self.add_text('%s ' % (' ' * len(lastname))) self.add_text(production.astext() + '\n') self.end_state(wrap=False) raise nodes.SkipNode()
def visit_title(self, node): if isinstance(node.parent, nodes.topic): self.body.append(self.defs['topic-title'][0]) elif isinstance(node.parent, nodes.sidebar): self.body.append(self.defs['sidebar-title'][0]) elif isinstance(node.parent, nodes.admonition): self.body.append('.IP "') elif self.section_level == 0: self._docinfo['title'] = node.astext() # document title for .TH self._docinfo['title_upper'] = node.astext().upper() raise nodes.SkipNode() elif self.section_level == 1: self.body.append('.SH ') for n in node.traverse(nodes.Text): n.parent.replace(n, nodes.Text(n.astext().upper())) else: self.body.append('.SS ')
def visit_title(self, node): parent = node.parent closing = u'</h3>' if isinstance(parent, nodes.Admonition): self.body.append(self.starttag(node, 'h3', CLASS='alert-title')) elif isinstance(node.parent, nodes.document): self.body.append(self.starttag(node, 'h1')) closing = u'</h1>' self.start_document_title = len(self.body) else: assert isinstance(parent, nodes.section), "expected a section node as parent to the title, found {}".format(parent) if self.first_title: self.first_title = False raise nodes.SkipNode() nodename = 'h{}'.format(self.section_level) self.body.append(self.starttag(node, nodename)) closing = u'</{}>'.format(nodename) self.context.append(closing)
def visit_document(self, node): self.document = node self.env = Environment.from_document_settings(self.document.settings) subtitle_node = self._detect_section_was_squashed_into_subtitle(node) if subtitle_node: version = subtitle_node.attributes["version_string"] rebuild_our_lost_section = nodes.section( "", nodes.title(version, version, classes=["release-version"]), **subtitle_node.attributes ) # note we are taking the nodes from the document and moving them # into the new section. nodes have a "parent" which means that # parent changes, which means we are mutating the internal # state of the document node. so use deepcopy() to avoid this # side effect; deepcopy() for these nodes seems to not be a # performance problem. rebuild_our_lost_section.extend([n.deepcopy() for n in node[2:]]) rebuild_our_lost_section.walkabout(self) raise nodes.SkipNode()
def visit_field_name(self, node): if self._in_docinfo: self._field_name = node.astext() raise nodes.SkipNode() else: self.body.append(self.defs['field_name'][0])
def visit_comment(self, node, sub=re.compile('-(?=-)').sub): self.body.append(self.comment(node.astext())) raise nodes.SkipNode()
def visit_field_body(self, node): if self._in_docinfo: name_normalized = self._field_name.lower().replace(" ", "_") self._docinfo_names[name_normalized] = self._field_name self.visit_docinfo_item(node, name_normalized) raise nodes.SkipNode()
def visit_target(self, node): raise nodes.SkipNode()
def visit_citation_reference(self, node): self.body.append('[' + node.astext() + ']') raise nodes.SkipNode()
def visit_label(self, node): raise nodes.SkipNode()
def visit_substitution_definition(self, node): """Internal only.""" raise nodes.SkipNode()
def visit_image(self, node): self.add_text('[image]') raise nodes.SkipNode()
def visit_meta(self, node): # only valid for HTML raise nodes.SkipNode()
def visit_citation_reference(self, node): self.add_text('[%s]' % node.astext()) raise nodes.SkipNode()
def visit_system_message(self, node): self.new_state(0) self.add_text('<SYSTEM MESSAGE: %s>' % node.astext()) self.end_state() raise nodes.SkipNode()
def visit_footnote_reference(self, node): self.add_text('[%s]' % node.astext()) raise nodes.SkipNode()
def visit_substitution_definition(self, node): raise nodes.SkipNode()
def visit_index(self, node): raise nodes.SkipNode()
def visit_footnote_reference(self, node): self.body.append('[' + self.deunicode(node.astext()) + ']') raise nodes.SkipNode()
def visit_target(self, node): # targets are in-document hyper targets, without any use for man-pages. raise nodes.SkipNode()
def visit_tabular_col_spec(self, node): raise nodes.SkipNode()
def visit_acks(self, node): self.new_state(0) self.add_text(', '.join(n.astext() for n in node.children[0].children) + '.') self.end_state() raise nodes.SkipNode()
def visit_raw(self, node): if node.get('format') == 'manpage': self.body.append(node.astext() + "\n") # Keep non-manpage raw text out of output: raise nodes.SkipNode()
def visit_colspec(self, node): self.table[0].append(node['colwidth']) raise nodes.SkipNode()
def visit_comment(self, node): raise nodes.SkipNode()
def visit_transition(self, node): indent = sum(self.stateindent) self.new_state(0) self.add_text('=' * (MAXWIDTH - indent)) self.end_state() raise nodes.SkipNode()