Repository: sphinx-doc/sphinx

Issue:
html_file_suffix for htmlhelp output
Currently html_file_suffix affects _html_ output, but the file suffix for the _htmlhelp_ output is always '.html' regardless. 

I think this is a bug because the docs state _"Options for HTML output. These options influence HTML as well as HTML Help output, and other builders that use Sphinx’s HTMLWriter class."_

I am currently porting a program's context sensitive help system from HTML Help to Sphinx (HTML Help output). The program accesses the files inside the CHM file directly with the HH_DISPLAY_TOPIC command. The trouble is the original file names had a '.htm' extension and the new Sphinx generated files are '.html'.


Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390?src=pr&el=h1) Report
> Merging [#5390](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390?src=pr&el=desc) into [master](https://codecov.io/gh/sphinx-doc/sphinx/commit/750e037ce6f2afeb0fc8e3956af91c8dc0b7b40b?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390/graphs/tree.svg?width=650&token=VFlFSELbkw&height=150&src=pr)](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master   #5390      +/-   ##
=========================================
+ Coverage   82.49%   82.5%   +<.01%     
=========================================
  Files         286     286              
  Lines       39131   39115      -16     
  Branches     5936    5932       -4     
=========================================
- Hits        32283   32271      -12     
+ Misses       5433    5431       -2     
+ Partials     1415    1413       -2
```


| [Impacted Files](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [sphinx/builders/html.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390/diff?src=pr&el=tree#diff-c3BoaW54L2J1aWxkZXJzL2h0bWwucHk=) | `84.49% <100%> (+0.01%)` | :arrow_up: |
| [sphinx/builders/htmlhelp.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390/diff?src=pr&el=tree#diff-c3BoaW54L2J1aWxkZXJzL2h0bWxoZWxwLnB5) | `97.72% <100%> (+0.03%)` | :arrow_up: |
| [sphinx/util/inspect.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390/diff?src=pr&el=tree#diff-c3BoaW54L3V0aWwvaW5zcGVjdC5weQ==) | `54.52% <0%> (-0.68%)` | :arrow_down: |
| [tests/test\_util\_inspect.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF91dGlsX2luc3BlY3QucHk=) | `81.56% <0%> (+0.66%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390?src=pr&el=footer). Last update [750e037...a501609](https://codecov.io/gh/sphinx-doc/sphinx/pull/5390?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGES b/CHANGES
index bcbf75d68..6310ab502 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 5dacdf3bb..da6b9474a 100644
--- a/sphinx/builders/html.py
+++ b/sphinx/builders/html.py
@@ -283,11 +283,14 @@ def init(self):
         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 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',


Test patch:
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'