diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-17 16:06:46 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-17 16:07:56 +0300 |
commit | de49b991f635faa0cf2cd07fae29bab3073b0662 (patch) | |
tree | 9f2d736beb2a7fd6439ba0ffe656fb62dccfdd31 /sphinx/io.py | |
parent | 0a199c08b834e8416ddec7d2b4b4f6e8950f8196 (diff) |
refactor: Use simple Input class
Diffstat (limited to 'sphinx/io.py')
-rw-r--r-- | sphinx/io.py | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/sphinx/io.py b/sphinx/io.py index 68ebe2b3c..2f942dcca 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -197,10 +197,15 @@ class SphinxBaseFileInput(FileInput): return UnicodeDecodeErrorHandler(self.env.docname)(error) -class SphinxFileInput(SphinxBaseFileInput): +class SphinxFileInput(FileInput): """A basic FileInput for Sphinx.""" supported = ('*',) # special source input + def __init__(self, *args, **kwargs): + # type: (Any, Any) -> None + kwargs['error_handler'] = 'sphinx' + super(SphinxFileInput, self).__init__(*args, **kwargs) + class SphinxRSTFileInput(SphinxBaseFileInput): """A reST FileInput for Sphinx. @@ -287,11 +292,8 @@ def read_doc(app, env, filename): error_handler = UnicodeDecodeErrorHandler(env.docname) codecs.register_error('sphinx', error_handler) # type: ignore - filetype = get_filetype(app.config.source_suffix, filename) - input_class = app.registry.get_source_input(filetype) reader = SphinxStandaloneReader(app) - source = input_class(app, env, source=None, source_path=filename, # type: ignore - encoding=env.config.source_encoding) + filetype = get_filetype(app.config.source_suffix, filename) parser = app.registry.create_source_parser(app, filetype) if parser.__class__.__name__ == 'CommonMarkParser' and parser.settings_spec == (): # a workaround for recommonmark @@ -301,23 +303,26 @@ def read_doc(app, env, filename): # CommonMarkParser. parser.settings_spec = RSTParser.settings_spec - pub = Publisher(reader=reader, # type: ignore - parser=parser, - writer=SphinxDummyWriter(), - source_class=SphinxDummySourceClass, - destination=NullOutput()) - pub.process_programmatic_settings(None, env.settings, None) - pub.set_source(source, filename) + input_class = app.registry.get_source_input(filetype) + if input_class: + # Sphinx-1.8 style + source = input_class(app, env, source=None, source_path=filename, # type: ignore + encoding=env.config.source_encoding) + pub = Publisher(reader=reader, # type: ignore + parser=parser, + writer=SphinxDummyWriter(), + source_class=SphinxDummySourceClass, + destination=NullOutput()) + pub.process_programmatic_settings(None, env.settings, None) + pub.set_source(source, filename) + else: + # Sphinx-2.0 style + pub = Publisher(reader=reader, + parser=parser, + writer=SphinxDummyWriter(), + source_class=SphinxFileInput) + pub.process_programmatic_settings(None, env.settings, None) + pub.set_source(source_path=filename) + pub.publish() return pub.document - - -def setup(app): - # type: (Sphinx) -> Dict[str, Any] - app.registry.add_source_input(SphinxFileInput) - - return { - 'version': 'builtin', - 'parallel_read_safe': True, - 'parallel_write_safe': True, - } |