Commits

Anonymous committed e068f22

New 'footnote' setting for epub_show_links.

  • Participants
  • Parent commits 3036821

Comments (0)

Files changed (3)

File doc/config.rst

    settings can have the following values:
 
    * ``'inline'`` -- display URLs inline in parentheses (default)
+   * ``'footnote'`` -- display URLs in footnotes
    * ``'no'`` -- do not display URLs
 
    .. versionadded:: 1.2

File sphinx/builders/epub.py

             node.attributes['ids'] = newids
 
     def add_visible_links(self, tree, show_urls='inline'):
-        """Append visible link targets after external links"""
+        """Add visible link targets for external links"""
+
+        def make_footnote_ref(doc, label):
+            """Create a footnote_reference node with children"""
+            footnote_ref = nodes.footnote_reference('[#]_')
+            footnote_ref.append(nodes.Text(label))
+            doc.note_autofootnote_ref(footnote_ref)
+            return footnote_ref
+
+        def make_footnote(doc, label, uri):
+            """Create a footnote node with children"""
+            footnote = nodes.footnote(uri)
+            para = nodes.paragraph()
+            para.append(nodes.Text(uri))
+            footnote.append(para)
+            footnote.insert(0, nodes.label('', label))
+            doc.note_autofootnote(footnote)
+            return footnote
+
         if show_urls == 'no':
             return
-
+        if show_urls == 'footnote':
+            doc = tree.traverse(nodes.document)[0]
+            # XXX search place to put footnotes
+            bottom = doc
+            nr = 1
         for node in tree.traverse(nodes.reference):
             uri = node.get('refuri', '')
             if (uri.startswith('http:') or uri.startswith('https:') or
                     link = nodes.inline(uri, uri)
                     link['classes'].append(_css_link_target_class)
                     node.parent.insert(idx, link)
+                elif show_urls == 'footnote':
+                    label = "#%d" % nr
+                    nr += 1
+                    footnote_ref = make_footnote_ref(doc, label)
+                    node.parent.insert(idx, footnote_ref)
+                    footnote = make_footnote(doc, label, uri)
+                    bottom.append(footnote)
+                    footnote_ref['refid'] = footnote['ids'][0]
+                    footnote.add_backref(footnote_ref['ids'][0])
 
     def write_doc(self, docname, doctree):
         """Write one document file.

File sphinx/quickstart.py

 # Scale large images.
 #epub_max_image_width = 0
 
-# If 'no', URL addresses will not be shown.
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
 #epub_show_urls = 'inline'
 
 # If false, no index is generated.