From e2f56a64a4a26a4ccf3c6ba809a6790f973a2ae7 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Sun, 5 Apr 2015 01:36:02 -0700 Subject: [PATCH 1/2] Email addresses should not be showed again if latex_show_urls is not False The latex output shows email addresses even the external links itself is an email address. For example, for an email address me@example.com, latex output will show it as "me@example.com (me@example.com)". This commit fixes this issue by removing the "mailto:" prefix before comparing the text and uri. --- sphinx/writers/latex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 291bedbab..68c909ac9 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1403,9 +1403,9 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append('\\href{%s}{' % self.encode_uri(uri)) # if configured, put the URL after the link show_urls = self.builder.config.latex_show_urls + if uri.startswith('mailto:'): + uri = uri[7:] if node.astext() != uri and show_urls and show_urls != 'no': - if uri.startswith('mailto:'): - uri = uri[7:] if show_urls == 'footnote' and not \ (self.in_footnote or self.in_caption): # obviously, footnotes in footnotes are not going to work From 0084004cfda246ff85557c4dceeb9b2f765d5d5c Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 11 Dec 2015 15:06:14 -0800 Subject: [PATCH 2/2] Add testing cases for the "latex_show_urls" option --- tests/root/conf.py | 1 + tests/root/footnote.txt | 12 ++++++++++++ tests/test_build_latex.py | 3 +++ 3 files changed, 16 insertions(+) diff --git a/tests/root/conf.py b/tests/root/conf.py index bdf2f8c8d..6ce196c3d 100644 --- a/tests/root/conf.py +++ b/tests/root/conf.py @@ -51,6 +51,7 @@ latex_documents = [ 'Georg Brandl \\and someone else', 'manual'), ] +latex_show_urls = 'footnote' latex_additional_files = ['svgimg.svg'] texinfo_documents = [ diff --git a/tests/root/footnote.txt b/tests/root/footnote.txt index 36ad3fadc..c30a5fe9c 100644 --- a/tests/root/footnote.txt +++ b/tests/root/footnote.txt @@ -35,6 +35,18 @@ footnotes in table * - VIDIOC_CROPCAP - Information about VIDIOC_CROPCAP +URLs as footnotes +----------------- + +`homepage `_ + +URLs should not be footnotes +---------------------------- + +GitHub Page: `https://github.com/sphinx-doc/sphinx `_ + +Mailing list: `sphinx-dev@googlegroups.com `_ + footenotes -------------------- diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 4b4eadbf5..00d3b82c1 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -318,6 +318,9 @@ def test_footnote(app, status, warning): assert ('\\end{threeparttable}\n\n' '\\footnotetext[4]{\nfootnotes in table caption\n}' '\\footnotetext[5]{\nfootnotes in table\n}' in result) + assert r'\href{http://sphinx.org}{homepage}\footnote{http://sphinx.org}' in result + assert r'\footnote{https://github.com/sphinx-doc/sphinx}' not in result + assert r'\footnote{sphinx-dev@googlegroups.com}' not in result @with_app(buildername='latex', testroot='references-in-caption')