Merge pull request #5390 from tk0miya/4018_htmlhelp_file_suffix

Fix #4018: htmlhelp: Add htmlhelp_file_suffix and htmlhelp_link_suffix
This commit is contained in:
Takeshi KOMIYA 2018-09-09 19:35:49 +09:00 committed by GitHub
commit ffaa528c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 6 deletions

View File

@ -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
----------

View File

@ -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:

View File

@ -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

View File

@ -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',

View File

@ -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'