diff --git a/CHANGES b/CHANGES index 783149961..1658a8cc5 100644 --- a/CHANGES +++ b/CHANGES @@ -27,6 +27,8 @@ Features added __ https://github.com/sphinx-contrib/sphinx-pretty-searchresults * #4182: autodoc: Support :confval:`suppress_warnings` +* #4018: htmlhelp: Add :confval:`htmlhelp_file_suffix` and + :confval:`htmlhelp_link_suffix` Bugs fixed ---------- diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index ee31d4f3b..636146013 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1347,6 +1347,19 @@ Options for HTML help output Output file base name for HTML help builder. Default is ``'pydoc'``. +.. confval:: htmlhelp_file_suffix + + This is the file name suffix for generated HTML help files. The + default is ``".html"``. + + .. versionadded:: 2.0 + +.. confval:: htmlhelp_link_suffix + + Suffix for generated links to HTML files. The default is ``".html"``. + + .. versionadded:: 2.0 + .. _applehelp-options: diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 17d2dbe7f..3c08cc818 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -283,11 +283,14 @@ class StandaloneHTMLBuilder(Builder): self.init_highlighter() self.init_css_files() self.init_js_files() - if self.config.html_file_suffix is not None: - self.out_suffix = self.config.html_file_suffix - if self.config.html_link_suffix is not None: - self.link_suffix = self.config.html_link_suffix + html_file_suffix = self.get_builder_config('file_suffix', 'html') + if html_file_suffix is not None: + self.out_suffix = html_file_suffix + + html_link_suffix = self.get_builder_config('link_suffix', 'html') + if html_link_suffix is not None: + self.link_suffix = html_link_suffix else: self.link_suffix = self.out_suffix diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 49d48361e..52600ca21 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -19,6 +19,7 @@ from docutils import nodes from sphinx import addnodes from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.config import string_classes from sphinx.environment.adapters.indexentries import IndexEntries from sphinx.locale import __ from sphinx.util import logging @@ -195,10 +196,10 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): def init(self): # type: () -> None - StandaloneHTMLBuilder.init(self) - # the output files for HTML help must be .html only + # the output files for HTML help is .html by default self.out_suffix = '.html' self.link_suffix = '.html' + StandaloneHTMLBuilder.init(self) # determine the correct locale setting locale = chm_locales.get(self.config.language) if locale is not None: @@ -341,6 +342,8 @@ def setup(app): app.add_builder(HTMLHelpBuilder) app.add_config_value('htmlhelp_basename', lambda self: make_filename(self.project), None) + app.add_config_value('htmlhelp_file_suffix', None, 'html', string_classes) + app.add_config_value('htmlhelp_link_suffix', None, 'html', string_classes) return { 'version': 'builtin', diff --git a/tests/test_build_htmlhelp.py b/tests/test_build_htmlhelp.py new file mode 100644 index 000000000..6eb7e3689 --- /dev/null +++ b/tests/test_build_htmlhelp.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +""" + test_build_htmlhelp + ~~~~~~~~~~~~~~~~~~~ + + Test the HTML Help builder and check output against XPath. + + :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest + + +@pytest.mark.sphinx('htmlhelp', testroot='basic') +def test_default_htmlhelp_file_suffix(app, warning): + assert app.builder.out_suffix == '.html' + + +@pytest.mark.sphinx('htmlhelp', testroot='basic', + confoverrides={'htmlhelp_file_suffix': '.htm'}) +def test_htmlhelp_file_suffix(app, warning): + assert app.builder.out_suffix == '.htm'