mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
add epub_show_urls option. This option is almost same as latex_show_urls.
This commit is contained in:
@@ -936,6 +936,14 @@ the `Dublin Core metadata <http://dublincore.org/>`_.
|
||||
|
||||
.. versionadded:: 1.2
|
||||
|
||||
.. confval:: epub_show_urls
|
||||
|
||||
Control whether to display URL addresses. This is very useful for printed
|
||||
copies of the manual. The setting can have the following values:
|
||||
|
||||
* ``'no'`` -- do not display URLs (default)
|
||||
* ``'inline'`` -- display URLs inline in parentheses
|
||||
|
||||
|
||||
.. _latex-options:
|
||||
|
||||
|
||||
@@ -281,8 +281,11 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
newids.append(self.fix_fragment('', id))
|
||||
node.attributes['ids'] = newids
|
||||
|
||||
def add_visible_links(self, tree):
|
||||
"""Append visible link targets after external links."""
|
||||
def add_visible_links(self, tree, show_urls='no'):
|
||||
"""Append visible link targets after external links"""
|
||||
if not show_urls or show_urls == 'no':
|
||||
return
|
||||
|
||||
for node in tree.traverse(nodes.reference):
|
||||
uri = node.get('refuri', '')
|
||||
if (uri.startswith('http:') or uri.startswith('https:') or
|
||||
@@ -290,9 +293,10 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
uri = _link_target_template % {'uri': uri}
|
||||
if uri:
|
||||
idx = node.parent.index(node) + 1
|
||||
link = nodes.inline(uri, uri)
|
||||
link['classes'].append(_css_link_target_class)
|
||||
node.parent.insert(idx, link)
|
||||
if show_urls == 'inline':
|
||||
link = nodes.inline(uri, uri)
|
||||
link['classes'].append(_css_link_target_class)
|
||||
node.parent.insert(idx, link)
|
||||
|
||||
def write_doc(self, docname, doctree):
|
||||
"""Write one document file.
|
||||
@@ -301,7 +305,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
and to add visible external links.
|
||||
"""
|
||||
self.fix_ids(doctree)
|
||||
self.add_visible_links(doctree)
|
||||
self.add_visible_links(doctree, self.config.epub_show_urls)
|
||||
return StandaloneHTMLBuilder.write_doc(self, docname, doctree)
|
||||
|
||||
def fix_genindex(self, tree):
|
||||
|
||||
@@ -142,6 +142,7 @@ class Config(object):
|
||||
epub_tocdup = (True, 'env'),
|
||||
epub_fix_images = (False, 'env'),
|
||||
epub_max_image_width = (0, 'env'),
|
||||
epub_show_urls = ('no', None),
|
||||
|
||||
# LaTeX options
|
||||
latex_documents = (lambda self: [(self.master_doc,
|
||||
|
||||
Reference in New Issue
Block a user