mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor parsing by docutils
This commit is contained in:
parent
d23f29f301
commit
1200ab48e1
@ -24,8 +24,6 @@ from collections import defaultdict
|
||||
from six import BytesIO, itervalues, class_types, next
|
||||
from six.moves import cPickle as pickle
|
||||
|
||||
from docutils.io import NullOutput
|
||||
from docutils.core import Publisher
|
||||
from docutils.utils import Reporter, get_source_line, normalize_language_tag
|
||||
from docutils.utils.smartquotes import smartchars
|
||||
from docutils.parsers.rst import roles
|
||||
@ -33,9 +31,7 @@ from docutils.parsers.rst.languages import en as english
|
||||
from docutils.frontend import OptionParser
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.io import (
|
||||
SphinxStandaloneReader, SphinxDummySourceClass, SphinxDummyWriter, SphinxFileInput
|
||||
)
|
||||
from sphinx.io import read_doc
|
||||
from sphinx.util import logging
|
||||
from sphinx.util import get_matching_docs, FilenameUniqDict, status_iterator
|
||||
from sphinx.util.nodes import is_translatable
|
||||
@ -711,22 +707,7 @@ class BuildEnvironment(object):
|
||||
location=docname)
|
||||
|
||||
codecs.register_error('sphinx', self.warn_and_replace) # type: ignore
|
||||
|
||||
# publish manually
|
||||
reader = SphinxStandaloneReader(self.app,
|
||||
parsers=self.app.registry.get_source_parsers())
|
||||
src_path = self.doc2path(docname)
|
||||
source = SphinxFileInput(app, self, source=None, source_path=src_path,
|
||||
encoding=self.config.source_encoding)
|
||||
pub = Publisher(reader=reader,
|
||||
writer=SphinxDummyWriter(),
|
||||
source_class=SphinxDummySourceClass,
|
||||
destination=NullOutput())
|
||||
pub.set_components(None, 'restructuredtext', None)
|
||||
pub.process_programmatic_settings(None, self.settings, None)
|
||||
pub.set_source(source, src_path)
|
||||
pub.publish()
|
||||
doctree = pub.document
|
||||
doctree = read_doc(self.app, self, self.doc2path(docname))
|
||||
|
||||
# post-processing
|
||||
for domain in itervalues(self.domains):
|
||||
|
21
sphinx/io.py
21
sphinx/io.py
@ -8,7 +8,8 @@
|
||||
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from docutils.io import FileInput
|
||||
from docutils.io import FileInput, NullOutput
|
||||
from docutils.core import Publisher
|
||||
from docutils.readers import standalone
|
||||
from docutils.writers import UnfilteredWriter
|
||||
from six import string_types, text_type, iteritems
|
||||
@ -185,3 +186,21 @@ class SphinxFileInput(FileInput):
|
||||
if self.env.config.rst_prolog:
|
||||
data = self.env.config.rst_prolog + '\n' + data
|
||||
return docinfo + data
|
||||
|
||||
|
||||
def read_doc(app, env, filename):
|
||||
"""Parse a document and convert to doctree."""
|
||||
# type: (Sphinx, BuildEnvironment, unicode) -> nodes.document
|
||||
reader = SphinxStandaloneReader(app, parsers=app.registry.get_source_parsers())
|
||||
source = SphinxFileInput(app, env, source=None, source_path=filename,
|
||||
encoding=env.config.source_encoding)
|
||||
|
||||
pub = Publisher(reader=reader,
|
||||
writer=SphinxDummyWriter(),
|
||||
source_class=SphinxDummySourceClass,
|
||||
destination=NullOutput())
|
||||
pub.set_components(None, 'restructuredtext', None)
|
||||
pub.process_programmatic_settings(None, env.settings, None)
|
||||
pub.set_source(source, filename)
|
||||
pub.publish()
|
||||
return pub.document
|
||||
|
Loading…
Reference in New Issue
Block a user