Commits

Jon Waltman committed e6bc92b

Use the standard Texinfo markup for footnotes.

Comments (0)

Files changed (1)

sphinx/writers/texinfo.py

 from sphinx import addnodes, __version__
 from sphinx.locale import versionlabels, _
 from sphinx.util import ustrftime
+from sphinx.writers.latex import collected_footnote
 
 
 COPYING = """\
         self.next_section_ids = set()
         self.escape_newlines = 0
         self.curfilestack = []
+        self.footnotestack = []
+        self.in_footnote = 0
 
     def finish(self):
         if self.previous_section is None:
                                          generate(content, collapsed)))
         self.indices.append((_('Index'), '\n@printindex ge\n'))
 
+    # this is copied from the latex writer
+    # TODO: move this to sphinx.util
+
+    def collect_footnotes(self, node):
+        fnotes = {}
+        def footnotes_under(n):
+            if isinstance(n, nodes.footnote):
+                yield n
+            else:
+                for c in n.children:
+                    if isinstance(c, addnodes.start_of_file):
+                        continue
+                    for k in footnotes_under(c):
+                        yield k
+        for fn in footnotes_under(node):
+            num = fn.children[0].astext().strip()
+            fnotes[num] = [collected_footnote(*fn.children), False]
+        return fnotes
+
     ## xref handling
 
     def get_short_id(self, id):
     ## Visiting
 
     def visit_document(self, node):
+        self.footnotestack.append(self.collect_footnotes(node))
         self.curfilestack.append(node.get('docname', ''))
         if 'docname' in node:
             self.add_anchor(':doc', node)
     def depart_document(self, node):
+        self.footnotestack.pop()
         self.curfilestack.pop()
 
     def visit_Text(self, node):
         self.body.append('\n\n')
 
     def visit_rubric(self, node):
+        if len(node.children) == 1 and node.children[0].astext() in \
+                ('Footnotes', _('Footnotes')):
+            raise nodes.SkipNode
         try:
             rubric = self.rubrics[self.section_level]
         except IndexError:
         else:
             uri = escape_arg(uri)
             name = escape_arg(name)
+            show_urls = 'footnote'
+            if self.in_footnote:
+                show_urls = 'inline'
             if not name or uri == name:
                 self.body.append('@indicateurl{%s}' % uri)
+            elif show_urls == 'inline':
+                self.body.append('@uref{%s,%s}' % (uri, name))
+            elif show_urls == 'no':
+                self.body.append('@uref{%s,,%s}' % (uri, name))
             else:
-                self.body.append('@uref{%s,%s}' % (uri, name))
+                self.body.append('%s@footnote{%s}' % (name, uri))
         raise nodes.SkipNode
 
     def depart_reference(self, node):
     ## Footnotes
 
     def visit_footnote(self, node):
-        self.visit_block_quote(node)
-    def depart_footnote(self, node):
-        self.depart_block_quote(node)
+        raise nodes.SkipNode
+
+    def visit_collected_footnote(self, node):
+        self.in_footnote += 1
+        self.body.append('@footnote{')
+    def depart_collected_footnote(self, node):
+        self.body.append('}')
+        self.in_footnote -= 1
 
     def visit_footnote_reference(self, node):
-        self.body.append('@w{(')
-    def depart_footnote_reference(self, node):
-        self.body.append(')}')
+        num = node.astext().strip()
+        try:
+            footnode, used = self.footnotestack[-1][num]
+        except (KeyError, IndexError):
+            raise nodes.SkipNode
+        # footnotes are repeated for each reference
+        footnode.walkabout(self)
+        raise nodes.SkipChildren
 
     def visit_citation(self, node):
         for id in node.get('ids'):
         # add a document target
         self.next_section_ids.add(':doc')
         self.curfilestack.append(node['docname'])
+        self.footnotestack.append(self.collect_footnotes(node))
     def depart_start_of_file(self, node):
         self.curfilestack.pop()
+        self.footnotestack.pop()
 
     def visit_centered(self, node):
         txt = escape_arg(node.astext())
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.