|
11 | 11 | from typing import TYPE_CHECKING, final
|
12 | 12 |
|
13 | 13 | from docutils import nodes
|
14 |
| -from docutils.utils import DependencyList |
15 | 14 |
|
16 | 15 | from sphinx._cli.util.colour import bold
|
17 | 16 | from sphinx.deprecation import _deprecation_warning
|
|
23 | 22 | from sphinx.environment.adapters.asset import ImageAdapter
|
24 | 23 | from sphinx.errors import SphinxError
|
25 | 24 | from sphinx.locale import __
|
26 |
| -from sphinx.util import ( |
27 |
| - get_filetype, |
28 |
| - logging, |
29 |
| - rst, |
30 |
| -) |
| 25 | +from sphinx.util import get_filetype, logging |
31 | 26 | from sphinx.util._importer import import_object
|
32 | 27 | from sphinx.util._pathlib import _StrPathProperty
|
33 | 28 | from sphinx.util.build_phase import BuildPhase
|
34 | 29 | from sphinx.util.display import progress_message, status_iterator
|
35 |
| -from sphinx.util.docutils import sphinx_domains |
| 30 | +from sphinx.util.docutils import _parse_str_to_doctree |
36 | 31 | from sphinx.util.i18n import CatalogRepository, docname_to_domain
|
37 | 32 | from sphinx.util.osutil import ensuredir, relative_uri, relpath
|
38 | 33 | from sphinx.util.parallel import (
|
@@ -644,26 +639,33 @@ def read_doc(self, docname: str, *, _cache: bool = True) -> None:
|
644 | 639 | if docutils_conf.is_file():
|
645 | 640 | env.note_dependency(docutils_conf)
|
646 | 641 |
|
647 |
| - filename = str(env.doc2path(docname)) |
648 |
| - filetype = get_filetype(self._app.config.source_suffix, filename) |
649 |
| - publisher = self._registry._get_publisher( |
650 |
| - filetype, config=self.config, env=self.env |
| 642 | + filename = env.doc2path(docname) |
| 643 | + |
| 644 | + # set up error_handler for the target document |
| 645 | + error_handler = _UnicodeDecodeErrorHandler(docname) |
| 646 | + codecs.register_error('sphinx', error_handler) # type: ignore[arg-type] |
| 647 | + |
| 648 | + # read the source file |
| 649 | + content = filename.read_text( |
| 650 | + encoding=env.settings['input_encoding'], errors='sphinx' |
651 | 651 | )
|
652 |
| - self.env.current_document._parser = publisher.parser |
653 |
| - # record_dependencies is mutable even though it is in settings, |
654 |
| - # explicitly re-initialise for each document |
655 |
| - publisher.settings.record_dependencies = DependencyList() |
656 |
| - with ( |
657 |
| - sphinx_domains(env), |
658 |
| - rst.default_role(docname, self.config.default_role), |
659 |
| - ): |
660 |
| - # set up error_handler for the target document |
661 |
| - error_handler = _UnicodeDecodeErrorHandler(docname) |
662 |
| - codecs.register_error('sphinx', error_handler) # type: ignore[arg-type] |
663 | 652 |
|
664 |
| - publisher.set_source(source_path=filename) |
665 |
| - publisher.publish() |
666 |
| - doctree = publisher.document |
| 653 | + # TODO: move the "source-read" event to here. |
| 654 | + |
| 655 | + filetype = get_filetype(self.config.source_suffix, filename) |
| 656 | + parser = self._registry.create_source_parser( |
| 657 | + filetype, config=self.config, env=env |
| 658 | + ) |
| 659 | + doctree = _parse_str_to_doctree( |
| 660 | + content, |
| 661 | + filename=filename, |
| 662 | + default_role=self.config.default_role, |
| 663 | + default_settings=env.settings, |
| 664 | + env=env, |
| 665 | + events=self.events, |
| 666 | + parser=parser, |
| 667 | + transforms=self._registry.get_transforms(), |
| 668 | + ) |
667 | 669 |
|
668 | 670 | # store time of reading, for outdated files detection
|
669 | 671 | env.all_docs[docname] = time.time_ns() // 1_000
|
|
0 commit comments