Set its URL as a default title value if URL appears in toctree

This commit is contained in:
tk0miya 2014-08-20 01:00:29 +09:00
parent 60911efe05
commit 7db168416b
2 changed files with 17 additions and 0 deletions

View File

@ -1217,6 +1217,8 @@ class BuildEnvironment:
try:
refdoc = None
if url_re.match(ref):
if title is None:
title = ref
reference = nodes.reference('', '', internal=False,
refuri=ref, anchorname='',
*[nodes.Text(title)])

View File

@ -459,3 +459,18 @@ def test_tocdepth_singlehtml(app):
for xpath, check, be_found in paths:
yield check_xpath, etree, fname, xpath, check, be_found
@with_app(buildername='html', srcdir='(empty)')
def test_url_in_toctree(app):
contents = (".. toctree::\n"
"\n"
" http://sphinx-doc.org/\n"
" Latest reference <http://sphinx-doc.org/latest/>\n")
(app.srcdir / 'contents.rst').write_text(contents, encoding='utf-8')
app.builder.build_all()
result = (app.outdir / 'contents.html').text(encoding='utf-8')
assert '<a class="reference external" href="http://sphinx-doc.org/">http://sphinx-doc.org/</a>' in result
assert '<a class="reference external" href="http://sphinx-doc.org/latest/">Latest reference</a>' in result