diff --git a/sphinx/environment.py b/sphinx/environment.py index 72f5d240e..9138c6f1b 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -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)]) diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 3753d05be..2c5f291ef 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -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 \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 'http://sphinx-doc.org/' in result + assert 'Latest reference' in result