Georg Brandl avatar Georg Brandl committed 2dfe268 Merge

Merged in jonwaltman/sphinx-info (pull request #5)

Comments (0)

Files changed (2)

sphinx/ext/graphviz.py

         raise nodes.SkipNode
     if fname is not None:
         self.body.append('\n\n@float\n')
-        if node.get('caption'):
+        caption = node.get('caption')
+        if caption:
             self.body.append('@caption{%s}\n' % self.escape_arg(caption))
         self.body.append('@image{%s,,,[graphviz],png}\n'
                          '@end float\n\n' % fname[:-4])

sphinx/writers/texinfo.py

 """
 
 import re
+import string
+import textwrap
 from os import path
-import textwrap
 
 from docutils import nodes, writers
 
         s = s.replace('@', '@@')
         s = s.replace('{', '@{')
         s = s.replace('}', '@}')
+        # prevent `` and '' quote conversion
+        s = s.replace('``', "`@w{`}")
+        s = s.replace("''", "'@w{'}")
         # prevent "--" from being converted to an "em dash"
         # s = s.replace('-', '@w{-}')
         return s
         s = ' '.join(s.split()).strip()
         return s
 
+    def ensure_eol(self):
+        """Ensure the last line in body is terminated by new line."""
+        if self.body and self.body[-1][-1:] != '\n':
+            self.body.append('\n')
+
     def format_menu_entry(self, name, node_name, desc):
         if name == node_name:
             s = '* %s:: ' % (name,)
     def visit_block_quote(self, node):
         self.body.append('\n@quotation\n')
     def depart_block_quote(self, node):
-        self.body.append('\n@end quotation\n\n')
+        self.ensure_eol()
+        self.body.append('@end quotation\n')
 
     def visit_literal_block(self, node):
         self.body.append('\n@example\n')
         bullet = node.get('bullet', '*')
         self.body.append('\n\n@itemize %s\n' % bullet)
     def depart_bullet_list(self, node):
-        self.body.append('\n@end itemize\n\n')
+        self.ensure_eol()
+        self.body.append('@end itemize\n')
 
     def visit_enumerated_list(self, node):
         # doesn't support Roman numerals
         start = node.get('start', starters.get(enum, ''))
         self.body.append('\n\n@enumerate %s\n' % start)
     def depart_enumerated_list(self, node):
-        self.body.append('\n@end enumerate\n\n')
+        self.ensure_eol()
+        self.body.append('@end enumerate\n')
 
     def visit_list_item(self, node):
-        self.body.append('\n@item\n')
+        self.body.append('\n@item ')
     def depart_list_item(self, node):
         pass
 
     def visit_option_list(self, node):
         self.body.append('\n\n@table @option\n')
     def depart_option_list(self, node):
-        self.body.append('\n@end table\n\n')
+        self.ensure_eol()
+        self.body.append('@end table\n')
 
     def visit_option_list_item(self, node):
         pass
     def visit_definition_list(self, node):
         self.body.append('\n\n@table @asis\n')
     def depart_definition_list(self, node):
-        self.body.append('\n@end table\n\n')
+        self.ensure_eol()
+        self.body.append('@end table\n')
 
     def visit_definition_list_item(self, node):
         self.at_item_x = '@item'
     def visit_field_list(self, node):
         self.body.append('\n\n@itemize @w\n')
     def depart_field_list(self, node):
-        self.body.append('\n@end itemize\n\n')
+        self.ensure_eol()
+        self.body.append('@end itemize\n')
 
     def visit_field(self, node):
         if not isinstance(node.parent, nodes.field_list):
         if not name:
             name = self.escape(node[0].astext())
         self.body.append('\n@cartouche\n'
-                         '@quotation %s\n' % name)
+                         '@quotation %s ' % name)
     def depart_admonition(self, node):
-        self.body.append('\n@end quotation\n'
-                         '@end cartouche\n\n')
+        self.ensure_eol()
+        self.body.append('@end quotation\n'
+                         '@end cartouche\n')
 
     def _make_visit_admonition(typ):
         def visit(self, node):
-            self.body.append('\n@cartouche\n'
-                             '@quotation %s\n' % self.escape(_(typ)))
+            self.visit_admonition(node, self.escape(_(typ)))
         return visit
 
     visit_attention = _make_visit_admonition('Attention')
         width = self.tex_image_length(attrs.get('width', ''))
         height = self.tex_image_length(attrs.get('height', ''))
         alt = self.escape_arg(attrs.get('alt', ''))
-        self.body.append('\n\n@image{%s,%s,%s,%s,%s}\n\n' %
+        self.body.append('\n@image{%s,%s,%s,%s,%s}\n' %
                          (name, width, height, alt, ext[1:]))
     def depart_image(self, node):
         pass
         pass
 
     def visit_comment(self, node):
+        self.body.append('\n')
         for line in node.astext().splitlines():
-            self.body.append('\n@c %s\n' % line)
+            self.body.append('@c %s\n' % line)
         raise nodes.SkipNode
 
     def visit_problematic(self, node):
         self.body.append('}')
 
     def visit_index(self, node):
+        # terminate the line but don't prevent paragraph breaks
+        if isinstance(node.parent, nodes.paragraph):
+            self.ensure_eol()
+        else:
+            self.body.append('\n')
         for entry in node['entries']:
             typ, text, tid, text2 = entry
             text = self.escape_menu(text)
     def visit_refcount(self, node):
         self.body.append('\n')
     def depart_refcount(self, node):
-        self.body.append('\n\n')
+        self.body.append('\n')
 
     def visit_versionmodified(self, node):
         intro = versionlabels[node['type']] % node['version']
             intro += ': '
         else:
             intro += '.'
-        self.body.append('\n\n%s' % self.escape(intro))
+        self.body.append('\n%s' % self.escape(intro))
     def depart_versionmodified(self, node):
-        self.body.append('\n\n')
+        self.body.append('\n')
 
     def visit_start_of_file(self, node):
         # add a document target
 
     ## Desc
 
-    desc_map = {
-        'cfunction':    'C Function',
-        'classmethod':  'Class Method',
-        'cmacro':       'C Macro',
-        'cmdoption':    'Command Option',
-        'cmember':      'C Member',
-        'confval':      'Configuration Value',
-        'ctype':        'C Type',
-        'cvar':         'C Variable',
-        'describe':     'Description',
-        'envvar':       'Environment Variable',
-        'staticmethod': 'Static Method',
-        'var':          'Variable',
-        }
-
     def visit_desc(self, node):
         self.at_deffnx = '@deffn'
     def depart_desc(self, node):
-        self.body.append('\n@end deffn\n\n')
+        self.ensure_eol()
+        self.body.append('@end deffn\n')
+
     def visit_desc_signature(self, node):
-        self.desctype = node.parent['desctype'].strip()
-        if self.desctype != 'describe':
+        objtype = node.parent['objtype']
+        if objtype != 'describe':
             for id in node.get('ids'):
                 self.add_anchor(id, node)
-        typ = _(self.desc_map.get(self.desctype,
-                                  self.desctype.capitalize()))
-        self.body.append('\n%s {%s} ' % (self.at_deffnx, self.escape_arg(typ)))
+        # use the full name of the objtype for the category
+        try:
+            domain = self.builder.env.domains[node.parent['domain']]
+            primary = self.builder.config.primary_domain
+            name = domain.get_type_name(domain.object_types[objtype],
+                                        primary == domain.name)
+        except KeyError:
+            name = objtype
+        category = self.escape_arg(string.capwords(name))
+        self.body.append('\n%s {%s} ' % (self.at_deffnx, category))
         self.at_deffnx = '@deffnx'
     def depart_desc_signature(self, node):
         self.body.append("\n")
             self.body.append(', ')
         else:
             self.first_param = 0
-        self.body.append(self.escape(node.astext()))
+        text = self.escape(node.astext())
+        # replace no-break spaces with normal ones
+        text = text.replace(u' ', '@w{ }')
+        self.body.append(text)
         raise nodes.SkipNode
 
     def visit_desc_optional(self, node):
         raise nodes.SkipNode
 
     def visit_desc_content(self, node):
-        self.body.append("\n")
+        pass
     def depart_desc_content(self, node):
         pass
 
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.