From b74b9cb5851564f2894e043e50b1f3176291f0b6 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 28 May 2016 14:46:13 +0900 Subject: [PATCH] Fix #2383: The generated footnote by `latex_show_urls` overflows lines --- CHANGES | 1 + sphinx/writers/latex.py | 7 +++++-- tests/test_build_latex.py | 9 +++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 078599dc6..fc34806d1 100644 --- a/CHANGES +++ b/CHANGES @@ -70,6 +70,7 @@ Bugs fixed * #2556: Xapian search does not work with Python 3 * #2581: The search doesn't work if language="es" (spanish) * #2382: Adjust spacing after abbreviations on figure numbers in LaTeX writer +* #2383: The generated footnote by `latex_show_urls` overflows lines Release 1.4.1 (released Apr 12, 2016) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 722ef6b21..12f8df60e 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -195,7 +195,7 @@ class ShowUrlsTransform(object): def create_footnote(self, uri): label = nodes.label('', '#') para = nodes.paragraph() - para.append(nodes.Text(uri)) + para.append(nodes.reference('', nodes.Text(uri), refuri=uri, nolinkurl=True)) footnote = nodes.footnote(uri, label, para, auto=1) footnote['names'].append('#') self.document.note_autofootnote(footnote) @@ -1636,7 +1636,10 @@ class LaTeXTranslator(nodes.NodeVisitor): self.context.append('') elif uri.startswith(URI_SCHEMES): if len(node) == 1 and uri == node[0]: - self.body.append('\\url{%s}' % self.encode_uri(uri)) + if node.get('nolinkurl'): + self.body.append('\\nolinkurl{%s}' % self.encode_uri(uri)) + else: + self.body.append('\\url{%s}' % self.encode_uri(uri)) raise nodes.SkipNode else: self.body.append('\\href{%s}{' % self.encode_uri(uri)) diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 5614315e7..90d87d9c5 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -497,21 +497,22 @@ def test_latex_show_urls_is_footnote(app, status, warning): assert 'First footnote: \\footnote[3]{\sphinxAtStartFootnote%\nFirst\n}' in result assert 'Second footnote: \\footnote[1]{\sphinxAtStartFootnote%\nSecond\n}' in result assert ('\\href{http://sphinx-doc.org/}{Sphinx}' - '\\footnote[4]{\sphinxAtStartFootnote%\nhttp://sphinx-doc.org/\n}' in result) + '\\footnote[4]{\sphinxAtStartFootnote%\n' + '\\nolinkurl{http://sphinx-doc.org/}\n}' in result) assert 'Third footnote: \\footnote[6]{\sphinxAtStartFootnote%\nThird\n}' in result assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}' '\\footnote[5]{\sphinxAtStartFootnote%\n' - 'http://sphinx-doc.org/\\textasciitilde{}test/\n}' in result) + '\\nolinkurl{http://sphinx-doc.org/~test/}\n}' in result) assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}\\protect\\footnotemark[8]}] ' '\\leavevmode\\footnotetext[8]{\sphinxAtStartFootnote%\n' - 'http://sphinx-doc.org/\n}\nDescription' in result) + '\\nolinkurl{http://sphinx-doc.org/}\n}\nDescription' in result) assert ('\\item[{Footnote in term \\protect\\footnotemark[10]}] ' '\\leavevmode\\footnotetext[10]{\sphinxAtStartFootnote%\n' 'Footnote in term\n}\nDescription' in result) assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\protect' '\\footnotemark[9]}] ' '\\leavevmode\\footnotetext[9]{\sphinxAtStartFootnote%\n' - 'http://sphinx-doc.org/\n}\nDescription' in result) + '\\nolinkurl{http://sphinx-doc.org/}\n}\nDescription' in result) assert ('\\url{https://github.com/sphinx-doc/sphinx}\n' in result) assert ('\\href{mailto:sphinx-dev@googlegroups.com}' '{sphinx-dev@googlegroups.com}\n' in result)