Jon Waltman avatar Jon Waltman committed 90afd26

Refactor Texinfo writer; remove ``add_text`` and ``rstrip`` methods.

Comments (0)

Files changed (1)

sphinx/writers/texinfo.py

     supported = ('texinfo', 'texi')
 
     settings_spec = (
-        'Texinfo Specific Options',
-        None,
-        (
-            ("Name of the resulting Info file to be created by 'makeinfo'.  "
-             "Should probably end with '.info'.",
-             ['--texinfo-filename'],
-             {'default': '', 'metavar': '<file>'}),
-
-            ('Specify the Info dir entry category.',
-             ['--texinfo-dir-category'],
-             {'default': 'Miscellaneous', 'metavar': '<name>'}),
-
-            ('The name to use for the Info dir entry.  '
-             'If not provided, no entry will be created.',
-             ['--texinfo-dir-entry'],
-             {'default': '', 'metavar': '<name>'}),
-
-            ('A brief description (one or two lines) to use for the '
-             'Info dir entry.',
-             ['--texinfo-dir-description'],
-             {'default': '', 'metavar': '<desc>'}),
-            )
-        )
+        'Texinfo Specific Options', None, (
+            ("Name of the Info file", ['--texinfo-filename'], {'default': ''}),
+            ('Dir entry', ['--texinfo-dir-entry'], {'default': ''}),
+            ('Description', ['--texinfo-dir-description'], {'default': ''}),
+            ('Category', ['--texinfo-dir-category'], {'default':
+                                                          'Miscellaneous'})))
 
     settings_defaults = {}
-    settings_default_overrides = {'docinfo_xform': 0}
 
     output = None
 
         for index in self.indices:
             name, content = index
             pointers = tuple([name] + self.rellinks[name])
-            self.add_text('\n@node %s,%s,%s,%s\n' % pointers)
-            self.add_text('@unnumbered %s\n\n%s\n' % (name, content))
+            self.body.append('\n@node %s,%s,%s,%s\n' % pointers)
+            self.body.append('@unnumbered %s\n\n%s\n' % (name, content))
 
         while self.referenced_ids:
-            # Handle xrefs with missing anchors
+            # handle xrefs with missing anchors
             r = self.referenced_ids.pop()
             if r not in self.written_ids:
-                self.add_text('@anchor{%s}@w{%s}\n' % (r, ' ' * 30))
+                self.body.append('@anchor{%s}@w{%s}\n' % (r, ' ' * 30))
         self.fragment = ''.join(self.body).strip() + '\n'
         self.elements['body'] = self.fragment
         self.output = TEMPLATE % self.elements
 
-
     ## Helper routines
 
     def init_settings(self):
                                ustrftime(self.builder.config.today_fmt
                                                 or _('%B %d, %Y')))
                 })
-        # Title
+        # title
         title = elements['title']
         if not title:
             title = self.document.next_node(nodes.title)
             title = (title and title.astext()) or '<untitled>'
         elements['title'] = escape_id(title) or '<untitled>'
-        # Filename
+        # filename
         if not elements['filename']:
             elements['filename'] = self.document.get('source') or 'untitled'
             if elements['filename'][-4:] in ('.txt', '.rst'):
                 elements['filename'] = elements['filename'][:-4]
             elements['filename'] += '.info'
-        # Direntry
+        # direntry
         if settings.texinfo_dir_entry:
             entry = self.format_menu_entry(
                 escape_menu(settings.texinfo_dir_entry),
         """Generates a unique id for each section.
 
         Assigns the attribute ``node_name`` to each section."""
-        # Must have a "Top" node
+        # must have a "Top" node
         self.document['node_name'] = 'Top'
         self.node_names['Top'] = 'Top'
         self.written_ids.update(('Top', 'top'))
-        # Each index is a node
+        # each index is a node
         for name, content in self.indices:
             self.node_names[name] = name
             self.written_ids.add(name)
-        # Each section is also a node
+        # each section is also a node
         for section in self.document.traverse(nodes.section):
             title = section.next_node(nodes.Titular)
             name = (title and title.astext()) or '<untitled>'
             assert 'node_name' in node and node['node_name']
             entries = [s['node_name'] for s in find_subsections(node)]
             node_menus[node['node_name']] = entries
-        # Try to find a suitable "Top" node
+        # try to find a suitable "Top" node
         title = self.document.next_node(nodes.title)
         top = (title and title.parent) or self.document
         if not isinstance(top, (nodes.document, nodes.section)):
             node_menus['Top'] = entries
             del node_menus[top['node_name']]
             top['node_name'] = 'Top'
-        # Handle the indices
+        # handle the indices
         for name, content in self.indices:
             node_menus[name] = ()
             node_menus['Top'].append(name)
         node_menus = self.node_menus
         for id, entries in node_menus.items():
             rellinks[id] = ['', '', '']
-        # Up's
+        # up's
         for id, entries in node_menus.items():
             for e in entries:
                 rellinks[e][2] = id
-        # Next's and prev's
+        # next's and prev's
         for id, entries in node_menus.items():
             for i, id in enumerate(entries):
                 # First child's prev is empty
                 # Last child's next is empty
                 if i != len(entries) - 1:
                     rellinks[id][0] = entries[i+1]
-        # Top's next is its first child
+        # top's next is its first child
         try:
             first = node_menus['Top'][0]
         except IndexError:
             rellinks['Top'][0] = first
             rellinks[first][1] = 'Top'
 
-    def add_text(self, text, fresh=False):
-        """Add some text to the output.
-
-        Optional argument ``fresh`` means to insert a newline before
-        the text if the last character out was not a newline."""
-        if fresh:
-            if self.body and not self.body[-1].endswith('\n'):
-                self.body.append('\n')
-        self.body.append(text)
-
-    def rstrip(self):
-        """Strip trailing whitespace from the current output."""
-        while self.body and not self.body[-1].strip():
-            del self.body[-1]
-        if not self.body:
-            return
-        self.body[-1] = self.body[-1].rstrip()
-
     def format_menu_entry(self, name, node_name, desc):
         if name == node_name:
             s = '* %s:: ' % (name,)
     def add_menu_entries(self, entries, reg=re.compile(r'\s+---?\s+')):
         for entry in entries:
             name = self.node_names[entry]
-            # Special formatting for entries that are divided by an em-dash
+            # special formatting for entries that are divided by an em-dash
             parts = reg.split(name, 1)
             if len(parts) == 2:
                 name, desc = parts
                 desc = ''
             name = escape_menu(name)
             desc = escape(desc)
-            me = self.format_menu_entry(name, entry, desc)
-            self.add_text(me, fresh=1)
+            self.body.append(self.format_menu_entry(name, entry, desc))
 
     def add_menu(self, node_name):
         entries = self.node_menus[node_name]
         if not entries:
             return
-        self.add_text('\n@menu\n')
+        self.body.append('\n@menu\n')
         self.add_menu_entries(entries)
-        if node_name != 'Top':
-            self.rstrip()
-            self.add_text('\n@end menu\n')
+        if not self.node_menus[entries[0]]:
+            self.body.append('\n@end menu\n')
             return
 
         def _add_detailed_menu(name):
             entries = self.node_menus[name]
             if not entries:
                 return
-            self.add_text('\n%s\n\n' % (escape(self.node_names[name],)))
+            self.body.append('\n%s\n\n' % (escape(self.node_names[name],)))
             self.add_menu_entries(entries)
             for subentry in entries:
                 _add_detailed_menu(subentry)
 
-        self.add_text('\n@detailmenu\n'
-                      ' --- The Detailed Node Listing ---\n')
+        if node_name == 'Top':
+            self.body.append('\n@detailmenu\n'
+                             ' --- The Detailed Node Listing ---\n')
         for entry in entries:
             _add_detailed_menu(entry)
-        self.rstrip()
-        self.add_text('\n@end detailmenu\n'
-                      '@end menu\n')
+        if node_name == 'Top':
+            self.body.append('\n@end detailmenu')
+        self.body.append('\n@end menu\n\n')
 
     def tex_image_length(self, width_str):
         match = re.match('(\d*\.?\d*)\s*(\S*)', width_str)
         sid = self.get_short_id(id)
         for id in (eid, sid):
             if id not in self.written_ids:
-                self.add_text('@anchor{%s}\n' % id)
+                self.body.append('@anchor{%s}\n' % id)
                 self.written_ids.add(id)
 
     def add_xref(self, id, name, node):
         name = escape_menu(name)
         sid = self.get_short_id(id)
-        self.add_text('@pxref{%s,,%s}' % (sid, name))
+        self.body.append('@pxref{%s,,%s}' % (sid, name))
         self.referenced_ids.add(sid)
         self.referenced_ids.add(escape_id(id))
 
         s = escape(node.astext())
         if self.escape_newlines:
             s = s.replace('\n', ' ')
-        self.add_text(s)
+        self.body.append(s)
     def depart_Text(self, node):
         pass
 
 
         node_name = node['node_name']
         pointers = tuple([node_name] + self.rellinks[node_name])
-        self.add_text('\n@node %s,%s,%s,%s\n' % pointers)
+        self.body.append('\n@node %s,%s,%s,%s\n' % pointers)
         for id in self.next_section_ids:
             self.add_anchor(id, node)
 
         parent = node.parent
         if isinstance(parent, nodes.table):
             return
-        if isinstance(parent, nodes.Admonition):
-            raise nodes.SkipNode
-        elif isinstance(parent, nodes.sidebar):
-            self.visit_rubric(node)
-        elif isinstance(parent, nodes.topic):
+        if isinstance(parent, (nodes.Admonition, nodes.sidebar, nodes.topic)):
             raise nodes.SkipNode
         elif not isinstance(parent, nodes.section):
             self.builder.warn(
                 heading = self.headings[self.section_level]
             except IndexError:
                 heading = self.headings[-1]
-            self.add_text('%s ' % heading, fresh=1)
+            self.body.append('\n%s ' % heading)
 
     def depart_title(self, node):
-        self.add_text('', fresh=1)
+        self.body.append('\n\n')
 
     def visit_rubric(self, node):
         try:
             rubric = self.rubrics[self.section_level]
         except IndexError:
             rubric = self.rubrics[-1]
-        self.add_text('%s ' % rubric, fresh=1)
+        self.body.append('\n%s ' % rubric)
     def depart_rubric(self, node):
-        self.add_text('', fresh=1)
+        self.body.append('\n\n')
 
     def visit_subtitle(self, node):
-        self.add_text('\n\n@noindent\n')
+        self.body.append('\n\n@noindent\n')
     def depart_subtitle(self, node):
-        self.add_text('\n\n')
+        self.body.append('\n\n')
 
     ## References
 
             uri = escape_arg(uri[7:])
             name = escape_arg(name)
             if not name or name == uri:
-                self.add_text('@email{%s}' % uri)
+                self.body.append('@email{%s}' % uri)
             else:
-                self.add_text('@email{%s,%s}' % (uri, name))
+                self.body.append('@email{%s,%s}' % (uri, name))
         elif uri.startswith('#'):
             # references to labels in the same document
             id = self.curfilestack[-1] + ':' + uri[1:]
             id = escape_id(id)
             name = escape_menu(name)
             if name == id:
-                self.add_text('@pxref{%s,,,%s}' % (id, uri))
+                self.body.append('@pxref{%s,,,%s}' % (id, uri))
             else:
-                self.add_text('@pxref{%s,,%s,%s}' % (id, name, uri))
+                self.body.append('@pxref{%s,,%s,%s}' % (id, name, uri))
         else:
             uri = escape_arg(uri)
             name = escape_arg(name)
             if not name or uri == name:
-                self.add_text('@indicateurl{%s}' % uri)
+                self.body.append('@indicateurl{%s}' % uri)
             else:
-                self.add_text('@uref{%s,%s}' % (uri, name))
+                self.body.append('@uref{%s,%s}' % (uri, name))
         raise nodes.SkipNode
 
     def depart_reference(self, node):
 
     def visit_title_reference(self, node):
         text = node.astext()
-        self.add_text('@cite{%s}' % escape_arg(text))
+        self.body.append('@cite{%s}' % escape_arg(text))
         raise nodes.SkipNode
-    def depart_title_reference(self, node):
-        pass
 
     ## Blocks
 
     def visit_paragraph(self, node):
         if 'continued' in node or isinstance(node.parent, nodes.compound):
-            self.add_text('@noindent\n', fresh=1)
+            self.body.append('\n@noindent')
+        self.body.append('\n')
     def depart_paragraph(self, node):
-        self.add_text('\n\n')
+        self.body.append('\n')
 
     def visit_block_quote(self, node):
-        self.rstrip()
-        self.add_text('\n\n@quotation\n')
+        self.body.append('\n@quotation\n')
     def depart_block_quote(self, node):
-        self.rstrip()
-        self.add_text('\n@end quotation\n\n')
+        self.body.append('\n@end quotation\n\n')
 
     def visit_literal_block(self, node):
-        self.rstrip()
-        self.add_text('\n\n@example\n')
+        self.body.append('\n@example\n')
     def depart_literal_block(self, node):
-        self.rstrip()
-        self.add_text('\n@end example\n\n'
-                      '@noindent\n')
+        self.body.append('\n@end example\n\n'
+                         '@noindent\n')
 
     visit_doctest_block = visit_literal_block
     depart_doctest_block = depart_literal_block
 
     def visit_line_block(self, node):
-        self.add_text('@display\n', fresh=1)
+        if not isinstance(node.parent, nodes.line_block):
+            self.body.append('\n\n')
+        self.body.append('@display\n')
     def depart_line_block(self, node):
-        self.add_text('@end display\n', fresh=1)
+        self.body.append('@end display\n')
+        if not isinstance(node.parent, nodes.line_block):
+            self.body.append('\n\n')
 
     def visit_line(self, node):
-        self.rstrip()
-        self.add_text('\n')
         self.escape_newlines += 1
     def depart_line(self, node):
-        self.add_text('@w{ }\n')
+        self.body.append('@w{ }\n')
         self.escape_newlines -= 1
 
     ## Inline
 
     def visit_strong(self, node):
-        self.add_text('@strong{')
+        self.body.append('@strong{')
     def depart_strong(self, node):
-        self.add_text('}')
+        self.body.append('}')
 
     def visit_emphasis(self, node):
-        self.add_text('@emph{')
+        self.body.append('@emph{')
     def depart_emphasis(self, node):
-        self.add_text('}')
+        self.body.append('}')
 
     def visit_literal(self, node):
-        self.add_text('@code{')
+        self.body.append('@code{')
     def depart_literal(self, node):
-        self.add_text('}')
+        self.body.append('}')
 
     def visit_superscript(self, node):
-        self.add_text('@w{^')
+        self.body.append('@w{^')
     def depart_superscript(self, node):
-        self.add_text('}')
+        self.body.append('}')
 
     def visit_subscript(self, node):
-        self.add_text('@w{[')
+        self.body.append('@w{[')
     def depart_subscript(self, node):
-        self.add_text(']}')
+        self.body.append(']}')
 
     ## Footnotes
 
         self.depart_block_quote(node)
 
     def visit_footnote_reference(self, node):
-        self.add_text('@w{(')
+        self.body.append('@w{(')
     def depart_footnote_reference(self, node):
-        self.add_text(')}')
+        self.body.append(')}')
 
     def visit_citation(self, node):
         for id in node.get('ids'):
         pass
 
     def visit_citation_reference(self, node):
-        self.add_text('@w{[')
+        self.body.append('@w{[')
     def depart_citation_reference(self, node):
-        self.add_text(']}')
+        self.body.append(']}')
 
     ## Lists
 
     def visit_bullet_list(self, node):
         bullet = node.get('bullet', '*')
-        self.rstrip()
-        self.add_text('\n\n@itemize %s\n' % bullet)
+        self.body.append('\n\n@itemize %s\n' % bullet)
     def depart_bullet_list(self, node):
-        self.rstrip()
-        self.add_text('\n@end itemize\n\n')
+        self.body.append('\n@end itemize\n\n')
 
     def visit_enumerated_list(self, node):
-        # Doesn't support Roman numerals
+        # doesn't support Roman numerals
         enum = node.get('enumtype', 'arabic')
         starters = {'arabic': '',
                     'loweralpha': 'a',
                     'upperalpha': 'A',}
         start = node.get('start', starters.get(enum, ''))
-        self.rstrip()
-        self.add_text('\n\n@enumerate %s\n' % start)
+        self.body.append('\n\n@enumerate %s\n' % start)
     def depart_enumerated_list(self, node):
-        self.rstrip()
-        self.add_text('\n@end enumerate\n\n')
+        self.body.append('\n@end enumerate\n\n')
 
     def visit_list_item(self, node):
-        self.rstrip()
-        self.add_text('\n@item\n')
+        self.body.append('\n@item\n')
     def depart_list_item(self, node):
         pass
 
     ## Option List
 
     def visit_option_list(self, node):
-        self.add_text('\n@table @option\n')
+        self.body.append('\n\n@table @option\n')
     def depart_option_list(self, node):
-        self.rstrip()
-        self.add_text('\n@end table\n\n')
+        self.body.append('\n@end table\n\n')
 
     def visit_option_list_item(self, node):
         pass
         pass
 
     def visit_option(self, node):
-        self.add_text(self.at_item_x + ' ', fresh=1)
+        self.body.append('\n%s ' % self.at_item_x)
         self.at_item_x = '@itemx'
     def depart_option(self, node):
         pass
         pass
 
     def visit_option_argument(self, node):
-        self.add_text(node.get('delimiter', ' '))
+        self.body.append(node.get('delimiter', ' '))
     def depart_option_argument(self, node):
         pass
 
     def visit_description(self, node):
-        self.add_text('', fresh=1)
+        self.body.append('\n')
     def depart_description(self, node):
         pass
 
     ## Definitions
 
     def visit_definition_list(self, node):
-        self.add_text('\n@table @asis\n')
+        self.body.append('\n\n@table @asis\n')
     def depart_definition_list(self, node):
-        self.rstrip()
-        self.add_text('\n@end table\n\n')
+        self.body.append('\n@end table\n\n')
 
     def visit_definition_list_item(self, node):
         self.at_item_x = '@item'
             if isinstance(n, (addnodes.index, nodes.target)):
                 n.walkabout(self)
                 node.remove(n)
-        self.add_text(self.at_item_x + ' ', fresh=1)
+        self.body.append('\n%s ' % self.at_item_x)
         self.at_item_x = '@itemx'
     def depart_term(self, node):
         pass
 
     def visit_termsep(self, node):
-        self.add_text(self.at_item_x + ' ', fresh=1)
+        self.body.append('\n%s ' % self.at_item_x)
+    def depart_termsep(self, node):
+        pass
 
     def visit_classifier(self, node):
-        self.add_text(' : ')
+        self.body.append(' : ')
     def depart_classifier(self, node):
         pass
 
     def visit_definition(self, node):
-        self.add_text('', fresh=1)
+        self.body.append('\n')
     def depart_definition(self, node):
         pass
 
     def visit_table(self, node):
         self.entry_sep = '@item'
     def depart_table(self, node):
-        self.rstrip()
-        self.add_text('\n@end multitable\n\n')
+        self.body.append('\n@end multitable\n\n')
 
     def visit_tabular_col_spec(self, node):
         pass
         self.colwidths.append(node['colwidth'])
         if len(self.colwidths) != self.n_cols:
             return
-        self.add_text('@multitable ', fresh=1)
+        self.body.append('\n\n@multitable ')
         for i, n in enumerate(self.colwidths):
-            self.add_text('{%s} ' %('x' * (n+2)))
+            self.body.append('{%s} ' %('x' * (n+2)))
     def depart_colspec(self, node):
         pass
 
         self.entry_sep = '@item'
 
     def visit_entry(self, node):
-        self.rstrip()
-        self.add_text('\n%s ' % self.entry_sep)
+        self.body.append('\n%s\n' % self.entry_sep)
         self.entry_sep = '@tab'
     def depart_entry(self, node):
         for i in xrange(node.get('morecols', 0)):
-            self.add_text('@tab\n', fresh=1)
-        self.add_text('', fresh=1)
+            self.body.append('\n@tab\n')
 
     ## Field Lists
 
     def visit_field_list(self, node):
-        self.add_text('\n@itemize @w\n')
+        self.body.append('\n\n@itemize @w\n')
     def depart_field_list(self, node):
-        self.rstrip()
-        self.add_text('\n@end itemize\n\n')
+        self.body.append('\n@end itemize\n\n')
 
     def visit_field(self, node):
         if not isinstance(node.parent, nodes.field_list):
-            self.visit_field_list(None)
+            self.visit_field_list(node)
     def depart_field(self, node):
         if not isinstance(node.parent, nodes.field_list):
-            self.depart_field_list(None)
+            self.depart_field_list(node)
 
     def visit_field_name(self, node):
-        self.add_text('@item ', fresh=1)
+        self.body.append('\n@item ')
     def depart_field_name(self, node):
-        self.add_text(':')
+        self.body.append(': ')
 
     def visit_field_body(self, node):
-        self.add_text('', fresh=1)
+        pass
     def depart_field_body(self, node):
         pass
 
     ## Admonitions
 
-    def visit_admonition(self, node):
-        title = escape(node[0].astext())
-        self.add_text('\n@cartouche\n'
-                       '@quotation %s\n' % title)
+    def visit_admonition(self, node, name=''):
+        if not name:
+            name = escape(node[0].astext())
+        self.body.append('\n@cartouche\n'
+                         '@quotation %s\n' % name)
     def depart_admonition(self, node):
-        self.rstrip()
-        self.add_text('\n@end quotation\n'
-                       '@end cartouche\n\n')
+        self.body.append('\n@end quotation\n'
+                         '@end cartouche\n\n')
 
     def _make_visit_admonition(typ):
         def visit(self, node):
-            title = escape(typ)
-            self.add_text('\n@cartouche\n'
-                          '@quotation %s\n' % title)
+            self.body.append('\n@cartouche\n'
+                             '@quotation %s\n' % escape(_(typ)))
         return visit
 
     visit_attention = _make_visit_admonition('Attention')
-    visit_caution   = _make_visit_admonition('Caution')
-    visit_danger    = _make_visit_admonition('Danger')
-    visit_error     = _make_visit_admonition('Error')
+    depart_attention = depart_admonition
+    visit_caution = _make_visit_admonition('Caution')
+    depart_caution = depart_admonition
+    visit_danger = _make_visit_admonition('Danger')
+    depart_danger = depart_admonition
+    visit_error = _make_visit_admonition('Error')
+    depart_error = depart_admonition
     visit_important = _make_visit_admonition('Important')
-    visit_note      = _make_visit_admonition('Note')
-    visit_tip       = _make_visit_admonition('Tip')
-    visit_hint      = _make_visit_admonition('Hint')
-    visit_warning   = _make_visit_admonition('Warning')
-
-    depart_attention = depart_admonition
-    depart_caution   = depart_admonition
-    depart_danger    = depart_admonition
-    depart_error     = depart_admonition
     depart_important = depart_admonition
-    depart_note      = depart_admonition
-    depart_tip       = depart_admonition
-    depart_hint      = depart_admonition
-    depart_warning   = depart_admonition
+    visit_note = _make_visit_admonition('Note')
+    depart_note = depart_admonition
+    visit_tip = _make_visit_admonition('Tip')
+    depart_tip = depart_admonition
+    visit_hint = _make_visit_admonition('Hint')
+    depart_hint = depart_admonition
+    visit_warning = _make_visit_admonition('Warning')
+    depart_warning = depart_admonition
 
     ## Misc
 
     def visit_docinfo(self, node):
-        # No 'docinfo_xform'
+        raise nodes.SkipNode
+
+    def visit_generated(self, node):
         raise nodes.SkipNode
 
     def visit_topic(self, node):
-        # Ignore TOC's since we have to have a "menu" anyway
+        # ignore TOC's since we have to have a "menu" anyway
         if 'contents' in node.get('classes', []):
             raise nodes.SkipNode
         title = node[0]
         self.visit_rubric(title)
-        self.add_text('%s\n' % escape(title.astext()))
-        self.visit_block_quote(node)
+        self.body.append('%s\n' % escape(title.astext()))
     def depart_topic(self, node):
-        self.depart_block_quote(node)
-
-    def visit_generated(self, node):
-        raise nodes.SkipNode
-    def depart_generated(self, node):
         pass
 
     def visit_transition(self, node):
-        self.add_text('\n\n@noindent\n'
-                      '@exdent @w{%s}\n\n'
-                      '@noindent\n' % ('_' * 70))
+        self.body.append('\n\n@exdent @w{    %s}\n\n' % ('* ' * 30))
     def depart_transition(self, node):
         pass
 
     def visit_attribution(self, node):
-        self.add_text('@flushright\n', fresh=1)
+        self.body.append('\n\n@center --- ')
     def depart_attribution(self, node):
-        self.add_text('@end flushright\n', fresh=1)
+        self.body.append('\n\n')
 
     def visit_raw(self, node):
         format = node.get('format', '').split()
         if 'texinfo' in format or 'texi' in format:
-            self.add_text(node.astext())
+            self.body.append(node.astext())
         raise nodes.SkipNode
-    def depart_raw(self, node):
-        pass
 
     def visit_figure(self, node):
-        self.add_text('\n@float Figure\n')
+        self.body.append('\n\n@float Figure\n')
     def depart_figure(self, node):
-        self.rstrip()
-        self.add_text('\n@end float\n\n')
+        self.body.append('\n@end float\n\n')
 
     def visit_caption(self, node):
         if not isinstance(node.parent, nodes.figure):
             self.builder.warn('caption not inside a figure.',
                               (self.curfilestack[-1], node.line))
             return
-        self.add_text('@caption{', fresh=1)
+        self.body.append('\n@caption{')
     def depart_caption(self, node):
         if isinstance(node.parent, nodes.figure):
-            self.rstrip()
-            self.add_text('}\n')
+            self.body.append('}\n')
 
     def visit_image(self, node):
         if node['uri'] in self.builder.images:
         width = self.tex_image_length(attrs.get('width', ''))
         height = self.tex_image_length(attrs.get('height', ''))
         alt = escape_arg(attrs.get('alt', ''))
-        self.add_text('\n\n@image{%s,%s,%s,%s,%s}\n\n' %
-                      (name, width, height, alt, ext[1:]))
+        self.body.append('\n\n@image{%s,%s,%s,%s,%s}\n\n' %
+                         (name, width, height, alt, ext[1:]))
     def depart_image(self, node):
         pass
 
         pass
 
     def visit_sidebar(self, node):
-        pass
+        self.visit_topic(node)
     def depart_sidebar(self, node):
-        pass
+        self.depart_topic(node)
 
     def visit_label(self, node):
-        self.add_text('@w{(')
+        self.body.append('@w{(')
     def depart_label(self, node):
-        self.add_text(')} ')
+        self.body.append(')} ')
 
     def visit_legend(self, node):
         pass
 
     def visit_substitution_definition(self, node):
         raise nodes.SkipNode
-    def depart_substitution_definition(self, node):
-        pass
 
     def visit_system_message(self, node):
-        self.add_text('\n\n@w{----------- System Message: %s/%s -----------} '
-                      '(%s, line %s)\n' % (
+        self.body.append('\n\n@w{----------- System Message: %s/%s -----------} '
+                         '(%s, line %s)\n' % (
                 node.get('type', '?'),
                 node.get('level', '?'),
                 escape(node.get('source', '?')),
 
     def visit_comment(self, node):
         for line in node.astext().splitlines():
-            self.add_text('@c %s\n' % line, fresh=1)
+            self.body.append('\n@c %s\n' % line)
         raise nodes.SkipNode
 
     def visit_problematic(self, node):
-        self.add_text('>')
+        self.body.append('>')
     def depart_problematic(self, node):
-        self.add_text('<')
+        self.body.append('<')
 
     def unimplemented_visit(self, node):
         self.builder.warn("unimplemented node type: %r" % node,
                           (self.curfilestack[-1], node.line))
 
     def unknown_visit(self, node):
-        self.builder.warn("Unknown node type: %r" % node,
+        self.builder.warn("unknown node type: %r" % node,
                           (self.curfilestack[-1], node.line))
     def unknown_departure(self, node):
         pass
                 s = production['tokenname'].ljust(maxlen) + ' ::='
                 lastname = production['tokenname']
             else:
-                s = '%s    ' % (' '*len(lastname))
-            self.add_text(escape(s))
-            self.add_text(escape(production.astext() + '\n'))
+                s = '%s    ' % (' '*maxlen)
+            self.body.append(escape(s))
+            self.body.append(escape(production.astext() + '\n'))
         self.depart_literal_block(None)
         raise nodes.SkipNode
-    def depart_productionlist(self, node):
-        pass
 
     def visit_literal_emphasis(self, node):
-        self.add_text('@code{')
+        self.body.append('@code{')
     def depart_literal_emphasis(self, node):
-        self.add_text('}')
+        self.body.append('}')
 
     def visit_module(self, node):
         modname = escape_id(node['modname'])
         self.add_anchor(modname, node)
+        self.body.append('}')
 
     def visit_index(self, node):
         for entry in node['entries']:
             typ, text, tid, text2 = entry
             text = escape_menu(text)
-            self.add_text('@geindex %s\n' % text)
+            self.body.append('@geindex %s\n' % text)
 
     def visit_autosummary_table(self, node):
         pass
         self.visit_transition(node)
 
     def visit_refcount(self, node):
-        self.add_text('\n')
+        self.body.append('\n')
     def depart_refcount(self, node):
-        self.add_text('\n\n')
+        self.body.append('\n\n')
 
     def visit_versionmodified(self, node):
         intro = versionlabels[node['type']] % node['version']
             intro += ': '
         else:
             intro += '.'
-        self.add_text('%s' % escape(intro), fresh=1)
+        self.body.append('\n\n%s' % escape(intro))
     def depart_versionmodified(self, node):
-        self.rstrip()
-        self.add_text('\n\n', fresh=1)
+        self.body.append('\n\n')
 
     def visit_start_of_file(self, node):
         # add a document target
 
     def visit_centered(self, node):
         txt = escape_arg(node.astext())
-        self.add_text('@center %s\n' % txt, fresh=1)
+        self.body.append('\n\n@center %s\n\n' % txt)
         raise nodes.SkipNode
-    def depart_centered(self, node):
-        pass
 
     def visit_seealso(self, node):
-        pass
+        self.visit_topic(node)
     def depart_seealso(self, node):
-        pass
+        self.depart_topic(node)
 
     def visit_meta(self, node):
         raise nodes.SkipNode
-    def depart_meta(self, node):
-        pass
 
     def visit_glossary(self, node):
         pass
     def visit_desc(self, node):
         self.at_deffnx = '@deffn'
     def depart_desc(self, node):
-        self.rstrip()
-        self.add_text('@end deffn\n\n', fresh=1)
+        self.body.append('\n@end deffn\n\n')
     def visit_desc_signature(self, node):
         self.desctype = node.parent['desctype'].strip()
         if self.desctype != 'describe':
             for id in node.get('ids'):
                 self.add_anchor(id, node)
-        typ = self.desc_map.get(self.desctype, self.desctype)
-        self.add_text('%s {%s} ' % (self.at_deffnx, escape_arg(typ)), fresh=1)
+        typ = _(self.desc_map.get(self.desctype,
+                                  self.desctype.capitalize()))
+        self.body.append('\n%s {%s} ' % (self.at_deffnx, escape_arg(typ)))
         self.at_deffnx = '@deffnx'
     def depart_desc_signature(self, node):
-        self.add_text("", fresh=1)
+        self.body.append("\n")
 
     def visit_desc_name(self, node):
         pass
         pass
 
     def visit_desc_returns(self, node):
-        self.add_text(' -> ')
+        self.body.append(' -> ')
     def depart_desc_returns(self, node):
         pass
 
     def visit_desc_parameterlist(self, node):
-        self.add_text(' (')
+        self.body.append(' (')
         self.first_param = 1
     def depart_desc_parameterlist(self, node):
-        self.add_text(')')
+        self.body.append(')')
 
     def visit_desc_parameter(self, node):
         if not self.first_param:
-            self.add_text(', ')
+            self.body.append(', ')
         else:
             self.first_param = 0
-        self.add_text(escape(node.astext()))
+        self.body.append(escape(node.astext()))
         raise nodes.SkipNode
-    def depart_desc_parameter(self, node):
-        pass
 
     def visit_desc_optional(self, node):
-        self.add_text('[')
+        self.body.append('[')
     def depart_desc_optional(self, node):
-        self.add_text(']')
+        self.body.append(']')
 
     def visit_desc_annotation(self, node):
         raise nodes.SkipNode
-    def depart_desc_annotation(self, node):
-        pass
 
     def visit_desc_content(self, node):
-        self.add_text("", fresh=1)
+        self.body.append("\n")
     def depart_desc_content(self, node):
         pass
 
     def visit_inline(self, node):
-        # stub
         pass
     def depart_inline(self, node):
         pass
 
     def visit_abbreviation(self, node):
-        self.add_text('@abbr{')
+        self.body.append('@abbr{')
         if node.hasattr('explanation'):
             self.context.append(', %s}' % escape_arg(node['explanation']))
         else:
         pass
 
     def visit_hlist(self, node):
-        # stub
         self.visit_bullet_list(node)
     def depart_hlist(self, node):
         self.depart_bullet_list(node)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.