mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #5349 from tk0miya/5348_support_remote_download_file
Fix #5348: download reference to remote file is not displayed
This commit is contained in:
commit
5eca61fd57
1
CHANGES
1
CHANGES
@ -24,6 +24,7 @@ Bugs fixed
|
|||||||
* #5325: latex: cross references has been broken by multiply labeled objects
|
* #5325: latex: cross references has been broken by multiply labeled objects
|
||||||
* C++, fixes for symbol addition and lookup. Lookup should no longer break
|
* C++, fixes for symbol addition and lookup. Lookup should no longer break
|
||||||
in partial builds. See also #5337.
|
in partial builds. See also #5337.
|
||||||
|
* #5348: download reference to remote file is not displayed
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -128,6 +128,9 @@ class DownloadFileCollector(EnvironmentCollector):
|
|||||||
"""Process downloadable file paths. """
|
"""Process downloadable file paths. """
|
||||||
for node in doctree.traverse(addnodes.download_reference):
|
for node in doctree.traverse(addnodes.download_reference):
|
||||||
targetname = node['reftarget']
|
targetname = node['reftarget']
|
||||||
|
if '://' in targetname:
|
||||||
|
node['refuri'] = targetname
|
||||||
|
else:
|
||||||
rel_filename, filename = app.env.relfn2path(targetname, app.env.docname)
|
rel_filename, filename = app.env.relfn2path(targetname, app.env.docname)
|
||||||
app.env.dependencies[app.env.docname].add(rel_filename)
|
app.env.dependencies[app.env.docname].add(rel_filename)
|
||||||
if not os.access(filename, os.R_OK):
|
if not os.access(filename, os.R_OK):
|
||||||
|
@ -564,10 +564,20 @@ class HTMLTranslator(BaseTranslator):
|
|||||||
|
|
||||||
def visit_download_reference(self, node):
|
def visit_download_reference(self, node):
|
||||||
# type: (nodes.Node) -> None
|
# type: (nodes.Node) -> None
|
||||||
if self.builder.download_support and node.hasattr('filename'):
|
atts = {'class': 'reference download',
|
||||||
self.body.append(
|
'download': ''}
|
||||||
'<a class="reference download internal" href="%s" download="">' %
|
|
||||||
posixpath.join(self.builder.dlpath, node['filename']))
|
if not self.builder.download_support:
|
||||||
|
self.context.append('')
|
||||||
|
elif 'refuri' in node:
|
||||||
|
atts['class'] += ' external'
|
||||||
|
atts['href'] = node['refuri']
|
||||||
|
self.body.append(self.starttag(node, 'a', '', **atts))
|
||||||
|
self.context.append('</a>')
|
||||||
|
elif 'filename' in node:
|
||||||
|
atts['class'] += ' internal'
|
||||||
|
atts['href'] = posixpath.join(self.builder.dlpath, node['filename'])
|
||||||
|
self.body.append(self.starttag(node, 'a', '', **atts))
|
||||||
self.context.append('</a>')
|
self.context.append('</a>')
|
||||||
else:
|
else:
|
||||||
self.context.append('')
|
self.context.append('')
|
||||||
|
@ -510,10 +510,20 @@ class HTML5Translator(BaseTranslator):
|
|||||||
|
|
||||||
def visit_download_reference(self, node):
|
def visit_download_reference(self, node):
|
||||||
# type: (nodes.Node) -> None
|
# type: (nodes.Node) -> None
|
||||||
if self.builder.download_support and node.hasattr('filename'):
|
atts = {'class': 'reference download',
|
||||||
self.body.append(
|
'download': ''}
|
||||||
'<a class="reference download internal" href="%s" download="">' %
|
|
||||||
posixpath.join(self.builder.dlpath, node['filename']))
|
if not self.builder.download_support:
|
||||||
|
self.context.append('')
|
||||||
|
elif 'refuri' in node:
|
||||||
|
atts['class'] += ' external'
|
||||||
|
atts['href'] = node['refuri']
|
||||||
|
self.body.append(self.starttag(node, 'a', '', **atts))
|
||||||
|
self.context.append('</a>')
|
||||||
|
elif 'filename' in node:
|
||||||
|
atts['class'] += ' internal'
|
||||||
|
atts['href'] = posixpath.join(self.builder.dlpath, node['filename'])
|
||||||
|
self.body.append(self.starttag(node, 'a', '', **atts))
|
||||||
self.context.append('</a>')
|
self.context.append('</a>')
|
||||||
else:
|
else:
|
||||||
self.context.append('')
|
self.context.append('')
|
||||||
|
7
tests/roots/test-roles-download/conf.py
Normal file
7
tests/roots/test-roles-download/conf.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
master_doc = 'index'
|
||||||
|
|
||||||
|
latex_documents = [
|
||||||
|
(master_doc, 'test.tex', 'The basic Sphinx documentation for testing', 'Sphinx', 'report')
|
||||||
|
]
|
0
tests/roots/test-roles-download/dummy.dat
Normal file
0
tests/roots/test-roles-download/dummy.dat
Normal file
6
tests/roots/test-roles-download/index.rst
Normal file
6
tests/roots/test-roles-download/index.rst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
test-roles-download
|
||||||
|
===================
|
||||||
|
|
||||||
|
* :download:`dummy.dat`
|
||||||
|
* :download:`not_found.dat`
|
||||||
|
* :download:`Sphinx logo <http://www.sphinx-doc.org/en/master/_static/sphinxheader.png>`
|
@ -354,6 +354,22 @@ def test_epub_css_files(app):
|
|||||||
'href="https://example.com/custom.css" />' not in content)
|
'href="https://example.com/custom.css" />' not in content)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('epub', testroot='roles-download')
|
||||||
|
def test_html_download_role(app, status, warning):
|
||||||
|
app.build()
|
||||||
|
assert not (app.outdir / '_downloads' / 'dummy.dat').exists()
|
||||||
|
|
||||||
|
content = (app.outdir / 'index.xhtml').text()
|
||||||
|
assert ('<li><p><code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">dummy.dat</span></code></p></li>' in content)
|
||||||
|
assert ('<li><p><code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">not_found.dat</span></code></p></li>' in content)
|
||||||
|
assert ('<li><p><code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">Sphinx</span> <span class="pre">logo</span></code>'
|
||||||
|
'<span class="link-target"> [http://www.sphinx-doc.org/en/master'
|
||||||
|
'/_static/sphinxheader.png]</span></p></li>' in content)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('epub')
|
@pytest.mark.sphinx('epub')
|
||||||
def test_run_epubcheck(app):
|
def test_run_epubcheck(app):
|
||||||
app.build()
|
app.build()
|
||||||
|
@ -1387,3 +1387,22 @@ def test_html_math_renderer_is_mismatched(make_app, app_params):
|
|||||||
assert False
|
assert False
|
||||||
except ConfigError as exc:
|
except ConfigError as exc:
|
||||||
assert str(exc) == "Unknown math_renderer 'imgmath' is given."
|
assert str(exc) == "Unknown math_renderer 'imgmath' is given."
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='roles-download')
|
||||||
|
def test_html_download_role(app, status, warning):
|
||||||
|
app.build()
|
||||||
|
assert (app.outdir / '_downloads' / 'dummy.dat').exists()
|
||||||
|
|
||||||
|
content = (app.outdir / 'index.html').text()
|
||||||
|
assert ('<li><a class="reference download internal" download="" '
|
||||||
|
'href="_downloads/dummy.dat">'
|
||||||
|
'<code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">dummy.dat</span></code></a></li>' in content)
|
||||||
|
assert ('<li><code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">not_found.dat</span></code></li>' in content)
|
||||||
|
assert ('<li><a class="reference download external" download="" '
|
||||||
|
'href="http://www.sphinx-doc.org/en/master/_static/sphinxheader.png">'
|
||||||
|
'<code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">Sphinx</span> <span class="pre">logo</span>'
|
||||||
|
'</code></a></li>' in content)
|
||||||
|
@ -321,3 +321,23 @@ def test_html5_output(app, cached_etree_parse, fname, expect):
|
|||||||
app.build()
|
app.build()
|
||||||
print(app.outdir / fname)
|
print(app.outdir / fname)
|
||||||
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
|
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='roles-download',
|
||||||
|
confoverrides={'html_experimental_html5_writer': True})
|
||||||
|
def test_html_download_role(app, status, warning):
|
||||||
|
app.build()
|
||||||
|
assert (app.outdir / '_downloads' / 'dummy.dat').exists()
|
||||||
|
|
||||||
|
content = (app.outdir / 'index.html').text()
|
||||||
|
assert ('<li><p><a class="reference download internal" download="" '
|
||||||
|
'href="_downloads/dummy.dat">'
|
||||||
|
'<code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">dummy.dat</span></code></a></p></li>' in content)
|
||||||
|
assert ('<li><p><code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">not_found.dat</span></code></p></li>' in content)
|
||||||
|
assert ('<li><p><a class="reference download external" download="" '
|
||||||
|
'href="http://www.sphinx-doc.org/en/master/_static/sphinxheader.png">'
|
||||||
|
'<code class="xref download docutils literal notranslate">'
|
||||||
|
'<span class="pre">Sphinx</span> <span class="pre">logo</span>'
|
||||||
|
'</code></a></p></li>' in content)
|
||||||
|
Loading…
Reference in New Issue
Block a user