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.
* `sphinx.ext.autodoc` crashes if target code imports * from mock modules
by `autodoc_mock_imports`.
* #1953: ``Sphinx.add_node`` does not add handlers the translator installed by
`html_translator_class`
Documentation
-------------

View File

@ -176,6 +176,12 @@ class Sphinx(object):
'This project needs at least Sphinx v%s and therefore cannot '
'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
# of code expect a confdir to be set
if self.confdir is None:

View File

@ -159,16 +159,11 @@ class StandaloneHTMLBuilder(Builder):
self.config.trim_doctest_flags)
def init_translator_class(self):
if self.translator_class is not None:
pass
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
else:
self.translator_class = HTMLTranslator
if self.translator_class is None:
if self.config.html_use_smartypants:
self.translator_class = SmartyPantsHTMLTranslator
else:
self.translator_class = HTMLTranslator
def get_outdated_docs(self):
cfgdict = dict((name, self.config[name])
@ -1209,7 +1204,6 @@ def setup(app):
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_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_additional_pages', {}, 'html')
app.add_config_value('html_use_modindex', True, 'html') # deprecated

View File

@ -108,6 +108,9 @@ class Config(object):
'table': l_('Table %s'),
'code-block': l_('Listing %s')},
'env'),
# pre-initialized confval for HTML builder
html_translator_class = (None, 'html', string_classes),
)
def __init__(self, dirname, filename, overrides, tags):
@ -221,7 +224,7 @@ class Config(object):
def pre_init_values(self, warn):
"""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:
try:
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',
confoverrides={'html_translator_class': 'ext.ExtHTMLTranslator'})
confoverrides={'html_translator_class': 'translator.ExtHTMLTranslator'})
def test_html_with_set_translator_for_html_and_html_translator_class(
app, status, warning):
# use set_translator() and html_translator_class.