Refactor sphinx.io.SphinxFileInput

This commit is contained in:
Takeshi KOMIYA 2016-06-12 12:50:45 +09:00
parent 8dde1eb02d
commit 715969a6c3

View File

@ -112,10 +112,9 @@ class SphinxFileInput(FileInput):
return data.decode(self.encoding, 'sphinx') # py2: decoding return data.decode(self.encoding, 'sphinx') # py2: decoding
def read(self): def read(self):
def get_parser_type(docname): def get_parser_type(source_path):
path = self.env.doc2path(docname)
for suffix in self.env.config.source_parsers: for suffix in self.env.config.source_parsers:
if path.endswith(suffix): if source_path.endswith(suffix):
parser_class = self.env.config.source_parsers[suffix] parser_class = self.env.config.source_parsers[suffix]
if isinstance(parser_class, string_types): if isinstance(parser_class, string_types):
parser_class = import_object(parser_class, 'source parser') parser_class = import_object(parser_class, 'source parser')
@ -129,7 +128,7 @@ class SphinxFileInput(FileInput):
self.app.emit('source-read', self.env.docname, arg) self.app.emit('source-read', self.env.docname, arg)
data = arg[0] data = arg[0]
docinfo, data = split_docinfo(data) docinfo, data = split_docinfo(data)
if 'restructuredtext' in get_parser_type(self.env.docname): if 'restructuredtext' in get_parser_type(self.source_path):
if self.env.config.rst_epilog: if self.env.config.rst_epilog:
data = data + '\n' + self.env.config.rst_epilog + '\n' data = data + '\n' + self.env.config.rst_epilog + '\n'
if self.env.config.rst_prolog: if self.env.config.rst_prolog: