mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
* fix code to pass test, add versionadded to doc, update CHANGES for pull request #229
This commit is contained in:
parent
9191ffaa50
commit
2e1c16486c
1
CHANGES
1
CHANGES
@ -42,6 +42,7 @@ Features added
|
|||||||
* PR#252, #1291: Windows color console support. Thanks to meu31.
|
* PR#252, #1291: Windows color console support. Thanks to meu31.
|
||||||
* PR#255: When generating latex references, also insert latex target/anchor
|
* PR#255: When generating latex references, also insert latex target/anchor
|
||||||
for the ids defined on the node. Thanks to Olivier Heurtier.
|
for the ids defined on the node. Thanks to Olivier Heurtier.
|
||||||
|
* PR#229: Allow registration of other translators. Thanks to Russell Sim.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -90,6 +90,8 @@ package.
|
|||||||
clashes with an existing translator an
|
clashes with an existing translator an
|
||||||
:exc:`sphinx.errors.ExtensionError` will be raised.
|
:exc:`sphinx.errors.ExtensionError` will be raised.
|
||||||
|
|
||||||
|
.. versionadded:: 1.3
|
||||||
|
|
||||||
.. method:: Sphinx.add_node(node, **kwds)
|
.. method:: Sphinx.add_node(node, **kwds)
|
||||||
|
|
||||||
Register a Docutils node class. This is necessary for Docutils internals.
|
Register a Docutils node class. This is necessary for Docutils internals.
|
||||||
|
@ -39,11 +39,6 @@ from sphinx.util import pycompat # imported for side-effects
|
|||||||
from sphinx.util.tags import Tags
|
from sphinx.util.tags import Tags
|
||||||
from sphinx.util.osutil import ENOENT
|
from sphinx.util.osutil import ENOENT
|
||||||
from sphinx.util.console import bold, lightgray, darkgray
|
from sphinx.util.console import bold, lightgray, darkgray
|
||||||
from sphinx.writers.html import HTMLTranslator
|
|
||||||
from sphinx.writers.latex import LaTeXTranslator
|
|
||||||
from sphinx.writers.text import TextTranslator
|
|
||||||
from sphinx.writers.manpage import ManualPageTranslator
|
|
||||||
from sphinx.writers.texinfo import TexinfoTranslator
|
|
||||||
|
|
||||||
if hasattr(sys, 'intern'):
|
if hasattr(sys, 'intern'):
|
||||||
intern = sys.intern
|
intern = sys.intern
|
||||||
@ -63,15 +58,6 @@ events = {
|
|||||||
'build-finished': 'exception',
|
'build-finished': 'exception',
|
||||||
}
|
}
|
||||||
|
|
||||||
TRANSLATORS = {
|
|
||||||
'html': HTMLTranslator,
|
|
||||||
'latex': LaTeXTranslator,
|
|
||||||
'text:': TextTranslator,
|
|
||||||
'man': ManualPageTranslator,
|
|
||||||
'texinfo': TexinfoTranslator
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FILENAME = 'conf.py'
|
CONFIG_FILENAME = 'conf.py'
|
||||||
ENV_PICKLE_FILENAME = 'environment.pickle'
|
ENV_PICKLE_FILENAME = 'environment.pickle'
|
||||||
|
|
||||||
@ -113,6 +99,8 @@ class Sphinx(object):
|
|||||||
self.warningiserror = warningiserror
|
self.warningiserror = warningiserror
|
||||||
|
|
||||||
self._events = events.copy()
|
self._events = events.copy()
|
||||||
|
self._translators = dict.fromkeys([
|
||||||
|
'html', 'latex', 'text', 'man', 'texinfo'])
|
||||||
|
|
||||||
# say hello to the world
|
# say hello to the world
|
||||||
self.info(bold('Running Sphinx v%s' % sphinx.__version__))
|
self.info(bold('Running Sphinx v%s' % sphinx.__version__))
|
||||||
@ -464,10 +452,10 @@ class Sphinx(object):
|
|||||||
self._events[name] = ''
|
self._events[name] = ''
|
||||||
|
|
||||||
def add_translator(self, name, translator_class):
|
def add_translator(self, name, translator_class):
|
||||||
if name in TRANSLATORS:
|
if name in self._translators:
|
||||||
raise ExtensionError('A Translator by the name '
|
raise ExtensionError('A Translator by the name '
|
||||||
'%s is already registered.' % name)
|
'%s is already registered.' % name)
|
||||||
TRANSLATORS[name] = translator_class
|
self._translators[name] = translator_class
|
||||||
|
|
||||||
def add_node(self, node, **kwds):
|
def add_node(self, node, **kwds):
|
||||||
self.debug('[app] adding node: %r', (node, kwds))
|
self.debug('[app] adding node: %r', (node, kwds))
|
||||||
@ -478,9 +466,23 @@ class Sphinx(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ExtensionError('Value for key %r must be a '
|
raise ExtensionError('Value for key %r must be a '
|
||||||
'(visit, depart) function tuple' % key)
|
'(visit, depart) function tuple' % key)
|
||||||
translator = TRANSLATORS.get(key)
|
translator = self._translators.get(key)
|
||||||
# ignore invalid keys for compatibility
|
if translator is not None:
|
||||||
if not translator:
|
pass
|
||||||
|
elif key == 'html':
|
||||||
|
from sphinx.writers.html import HTMLTranslator as translator
|
||||||
|
elif key == 'latex':
|
||||||
|
from sphinx.writers.latex import LaTeXTranslator as translator
|
||||||
|
elif key == 'text':
|
||||||
|
from sphinx.writers.text import TextTranslator as translator
|
||||||
|
elif key == 'man':
|
||||||
|
from sphinx.writers.manpage import ManualPageTranslator \
|
||||||
|
as translator
|
||||||
|
elif key == 'texinfo':
|
||||||
|
from sphinx.writers.texinfo import TexinfoTranslator \
|
||||||
|
as translator
|
||||||
|
else:
|
||||||
|
# ignore invalid keys for compatibility
|
||||||
continue
|
continue
|
||||||
setattr(translator, 'visit_'+node.__name__, visit)
|
setattr(translator, 'visit_'+node.__name__, visit)
|
||||||
if depart:
|
if depart:
|
||||||
|
Loading…
Reference in New Issue
Block a user