Fix #2337: Use `\url{URL} macro instead of \href{URL}{URL}` in LaTeX writer

This commit is contained in:
Takeshi KOMIYA
2016-03-04 15:38:41 +09:00
parent 4899214238
commit 0211e19ae6
4 changed files with 13 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ Release 1.4 alpha2 (in development)
Incompatible changes
--------------------
* #2327: `latex_use_parts` is deprecated now. Use `latex_toplevel_sectioning` instead.
* #2337: Use ``\url{URL}`` macro instead of ``\href{URL}{URL}`` in LaTeX writer.
Features added
--------------

View File

@@ -449,6 +449,9 @@
% \capstart for figures that actually have a caption.)
\RequirePackage{hypcap}
% Set up styles of URL: it should be placed after hyperref
\urlstyle{same}
% From docutils.writers.latex2e
% inline markup (custom roles)
% \DUrole{#1}{#2} tries \DUrole#1{#2}

View File

@@ -1599,8 +1599,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
if self.in_title or not uri:
self.context.append('')
elif uri.startswith(URI_SCHEMES):
self.body.append('\\href{%s}{' % self.encode_uri(uri))
self.context.append('}')
if len(node) == 1 and uri == node[0]:
self.body.append('\\url{%s}' % self.encode_uri(uri))
raise nodes.SkipNode
else:
self.body.append('\\href{%s}{' % self.encode_uri(uri))
self.context.append('}')
elif uri.startswith('#'):
# references to labels in the same document
id = self.curfilestack[-1] + ':' + uri[1:]

View File

@@ -469,8 +469,7 @@ def test_latex_show_urls_is_inline(app, status, warning):
'Footnote in term\n}\nDescription' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist} '
'(http://sphinx-doc.org/)}] \\leavevmode\nDescription' in result)
assert ('\\href{https://github.com/sphinx-doc/sphinx}'
'{https://github.com/sphinx-doc/sphinx}\n' in result)
assert ('\\url{https://github.com/sphinx-doc/sphinx}\n' in result)
assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
'{sphinx-dev@googlegroups.com}' in result)
@@ -512,8 +511,7 @@ def test_latex_show_urls_is_footnote(app, status, warning):
'\\footnotemark[9]}] '
'\\leavevmode\\footnotetext[9]{\sphinxAtStartFootnote%\n'
'http://sphinx-doc.org/\n}\nDescription' in result)
assert ('\\href{https://github.com/sphinx-doc/sphinx}'
'{https://github.com/sphinx-doc/sphinx}\n' 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)
@@ -549,8 +547,7 @@ def test_latex_show_urls_is_no(app, status, warning):
'Footnote in term\n}\nDescription' in result)
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}}] '
'\\leavevmode\nDescription' in result)
assert ('\\href{https://github.com/sphinx-doc/sphinx}'
'{https://github.com/sphinx-doc/sphinx}\n' 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)