summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/io.py13
-rw-r--r--sphinx/registry.py19
2 files changed, 15 insertions, 17 deletions
diff --git a/sphinx/io.py b/sphinx/io.py
index 47e701f35..71701e10d 100644
--- a/sphinx/io.py
+++ b/sphinx/io.py
@@ -140,22 +140,15 @@ class SphinxFileInput(FileInput):
def read(self):
# type: () -> unicode
- def get_parser_type(source_path):
- # type: (unicode) -> Tuple[unicode]
- for suffix, parser_class in iteritems(self.app.registry.get_source_parsers()):
- if source_path.endswith(suffix):
- if isinstance(parser_class, string_types):
- parser_class = import_object(parser_class, 'source parser') # type: ignore # NOQA
- return parser_class.supported
- return ('restructuredtext',)
-
data = FileInput.read(self)
if self.app:
arg = [data]
self.app.emit('source-read', self.env.docname, arg)
data = arg[0]
+
+ parser = self.app.registry.get_source_parser(self.source_path)
docinfo, data = split_docinfo(data)
- if 'restructuredtext' in get_parser_type(self.source_path):
+ if 'restructuredtext' in parser.supported:
if self.env.config.rst_epilog:
data = data + '\n' + self.env.config.rst_epilog + '\n'
if self.env.config.rst_prolog:
diff --git a/sphinx/registry.py b/sphinx/registry.py
index c8ce4ad5e..3723bcc29 100644
--- a/sphinx/registry.py
+++ b/sphinx/registry.py
@@ -157,13 +157,13 @@ class SphinxComponentRegistry(object):
stddomain.object_types[directivename] = ObjType(objname or directivename, rolename)
def add_source_parser(self, suffix, parser):
- # type: (unicode, Parser) -> None
+ # type: (unicode, Type[Parser]) -> None
if suffix in self.source_parsers:
raise ExtensionError(__('source_parser for %r is already registered') % suffix)
self.source_parsers[suffix] = parser
- def create_source_parser(self, app, filename):
- # type: (Sphinx, unicode) -> Parser
+ def get_source_parser(self, filename):
+ # type: (unicode) -> Type[Parser]
for suffix, parser_class in iteritems(self.source_parsers):
if filename.endswith(suffix):
break
@@ -176,15 +176,20 @@ class SphinxComponentRegistry(object):
else:
if isinstance(parser_class, string_types):
parser_class = import_object(parser_class, 'source parser') # type: ignore
- parser = parser_class()
- if isinstance(parser, SphinxParser):
- parser.set_application(app)
- return parser
+ return parser_class
def get_source_parsers(self):
# type: () -> Dict[unicode, Parser]
return self.source_parsers
+ def create_source_parser(self, app, filename):
+ # type: (Sphinx, unicode) -> Parser
+ parser_class = self.get_source_parser(filename)
+ parser = parser_class()
+ if isinstance(parser, SphinxParser):
+ parser.set_application(app)
+ return parser
+
def add_translator(self, name, translator):
# type: (unicode, Type[nodes.NodeVisitor]) -> None
self.translators[name] = translator