Fix #1953: `Sphinx.add_node does not add handlers the translator installed by html_translator_class`

This commit is contained in:
Takeshi KOMIYA
2016-08-19 00:45:45 +09:00
parent 6911611f8d
commit 05caa0f037
5 changed files with 18 additions and 13 deletions

View File

@@ -105,6 +105,8 @@ Bugs fixed
module. Now Sphinx installs them on running application. module. Now Sphinx installs them on running application.
* `sphinx.ext.autodoc` crashes if target code imports * from mock modules * `sphinx.ext.autodoc` crashes if target code imports * from mock modules
by `autodoc_mock_imports`. by `autodoc_mock_imports`.
* #1953: ``Sphinx.add_node`` does not add handlers the translator installed by
`html_translator_class`
Documentation Documentation
------------- -------------

View File

@@ -176,6 +176,12 @@ class Sphinx(object):
'This project needs at least Sphinx v%s and therefore cannot ' 'This project needs at least Sphinx v%s and therefore cannot '
'be built with this version.' % self.config.needs_sphinx) 'be built with this version.' % self.config.needs_sphinx)
# force preload html_translator_class
if self.config.html_translator_class:
translator_class = self.import_object(self.config.html_translator_class,
'html_translator_class setting')
self.set_translator('html', translator_class)
# set confdir to srcdir if -C given (!= no confdir); a few pieces # set confdir to srcdir if -C given (!= no confdir); a few pieces
# of code expect a confdir to be set # of code expect a confdir to be set
if self.confdir is None: if self.confdir is None:

View File

@@ -159,13 +159,8 @@ class StandaloneHTMLBuilder(Builder):
self.config.trim_doctest_flags) self.config.trim_doctest_flags)
def init_translator_class(self): def init_translator_class(self):
if self.translator_class is not None: if self.translator_class is None:
pass if self.config.html_use_smartypants:
elif self.config.html_translator_class:
self.translator_class = self.app.import_object(
self.config.html_translator_class,
'html_translator_class setting')
elif self.config.html_use_smartypants:
self.translator_class = SmartyPantsHTMLTranslator self.translator_class = SmartyPantsHTMLTranslator
else: else:
self.translator_class = HTMLTranslator self.translator_class = HTMLTranslator
@@ -1209,7 +1204,6 @@ def setup(app):
app.add_config_value('html_extra_path', [], 'html') app.add_config_value('html_extra_path', [], 'html')
app.add_config_value('html_last_updated_fmt', None, 'html', string_classes) app.add_config_value('html_last_updated_fmt', None, 'html', string_classes)
app.add_config_value('html_use_smartypants', True, 'html') app.add_config_value('html_use_smartypants', True, 'html')
app.add_config_value('html_translator_class', None, 'html', string_classes)
app.add_config_value('html_sidebars', {}, 'html') app.add_config_value('html_sidebars', {}, 'html')
app.add_config_value('html_additional_pages', {}, 'html') app.add_config_value('html_additional_pages', {}, 'html')
app.add_config_value('html_use_modindex', True, 'html') # deprecated app.add_config_value('html_use_modindex', True, 'html') # deprecated

View File

@@ -108,6 +108,9 @@ class Config(object):
'table': l_('Table %s'), 'table': l_('Table %s'),
'code-block': l_('Listing %s')}, 'code-block': l_('Listing %s')},
'env'), 'env'),
# pre-initialized confval for HTML builder
html_translator_class = (None, 'html', string_classes),
) )
def __init__(self, dirname, filename, overrides, tags): def __init__(self, dirname, filename, overrides, tags):
@@ -221,7 +224,7 @@ class Config(object):
def pre_init_values(self, warn): def pre_init_values(self, warn):
"""Initialize some limited config variables before loading extensions""" """Initialize some limited config variables before loading extensions"""
variables = ['needs_sphinx', 'suppress_warnings'] variables = ['needs_sphinx', 'suppress_warnings', 'html_translator_class']
for name in variables: for name in variables:
try: try:
if name in self.overrides: if name in self.overrides:

View File

@@ -57,7 +57,7 @@ def test_html_with_set_translator_for_html_(app, status, warning):
@with_app('html', testroot='api-set-translator', @with_app('html', testroot='api-set-translator',
confoverrides={'html_translator_class': 'ext.ExtHTMLTranslator'}) confoverrides={'html_translator_class': 'translator.ExtHTMLTranslator'})
def test_html_with_set_translator_for_html_and_html_translator_class( def test_html_with_set_translator_for_html_and_html_translator_class(
app, status, warning): app, status, warning):
# use set_translator() and html_translator_class. # use set_translator() and html_translator_class.