Add option html_sourcelink_txt

This commit is contained in:
Matthias Geier 2016-03-29 12:52:21 +02:00
parent 7886ecc994
commit 86615e1f09
4 changed files with 31 additions and 5 deletions

View File

@ -870,6 +870,13 @@ that use Sphinx's HTMLWriter class.
.. versionadded:: 0.6
.. confval:: html_sourcelink_txt
If true, ``.txt`` is appended to source links (see
:confval:`html_show_sourcelink`). Default is ``True``.
.. versionadded:: 1.5
.. confval:: html_use_opensearch
If nonempty, an `OpenSearch <http://www.opensearch.org/Home>`_ description file will be

View File

@ -402,15 +402,21 @@ class StandaloneHTMLBuilder(Builder):
# title rendered as HTML
title = self.env.longtitles.get(docname)
title = title and self.render_partial(title)['title'] or ''
# Suffix for the document
source_suffix = path.splitext(self.env.doc2path(docname))[1]
# the name for the copied source
sourcename = self.config.html_copy_source and docname + '.txt' or ''
if self.config.html_copy_source:
sourcename = docname + source_suffix
if self.config.html_sourcelink_txt and source_suffix != '.txt':
sourcename += '.txt'
else:
sourcename = ''
# metadata for the document
meta = self.env.metadata.get(docname)
# Suffix for the document
source_suffix = '.' + self.env.doc2path(docname).split('.')[-1]
# local TOC and global TOC tree
self_toc = self.env.get_toc_for(docname, self)
toc = self.render_partial(self_toc)['fragment']

View File

@ -121,6 +121,7 @@ class Config(object):
html_split_index = (False, 'html'),
html_copy_source = (True, 'html'),
html_show_sourcelink = (True, 'html'),
html_sourcelink_txt = (True, 'html'),
html_use_opensearch = ('', 'html'),
html_file_suffix = (None, 'html', string_classes),
html_link_suffix = (None, 'html', string_classes),

View File

@ -319,7 +319,7 @@ HTML_XPATH = {
],
'otherext.html': [
(".//h1", "Generated section"),
(".//a[@href='_sources/otherext.txt']", ''),
(".//a[@href='_sources/otherext.foo.txt']", ''),
]
}
@ -987,3 +987,15 @@ def test_html_extra_path(app, status, warning):
assert (app.outdir / 'rimg.png').exists()
assert not (app.outdir / '_build/index.html').exists()
assert (app.outdir / 'background.png').exists()
@with_app(buildername='html', confoverrides={'html_sourcelink_txt': False})
def test_html_sourcelink_txt(app, status, warning):
app.builder.build_all()
content_otherext = (app.outdir / 'otherext.html').text()
content_images = (app.outdir / 'images.html').text()
assert '<a href="_sources/otherext.foo"' in content_otherext
assert '<a href="_sources/images.txt"' in content_images
assert (app.outdir / '_sources' / 'otherext.foo').exists()
assert (app.outdir / '_sources' / 'images.txt').exists()