Debian Codegraph @

docutils/readers/doctree.py

raw symbols SCIP
1 # $Id: doctree.py 10136 2025-05-20 15:48:27Z milde $
2 # Author: Martin Blais <[email protected]>
3 # Copyright: This module has been placed in the public domain.
4
5 """Reader for existing document trees."""
6
7 from __future__ import annotations
8
9 __docformat__ = 'reStructuredText'
10
11 from docutils import readers, utils, transforms
12
13
14 class Reader(readers.ReReader):
15
16 """
17 Adapt the Reader API for an existing document tree.
18
19 The existing document tree must be passed as the ``source`` parameter to
20 the `docutils.core.Publisher` initializer, wrapped in a
21 `docutils.io.DocTreeInput` object::
22
23 pub = docutils.core.Publisher(
24 ..., source=docutils.io.DocTreeInput(document), ...)
25
26 The original document settings are overridden; if you want to use the
27 settings of the original document, pass ``settings=document.settings`` to
28 the Publisher call above.
29 """
30
31 supported = ('doctree',)
32
33 config_section = 'doctree reader'
34 config_section_dependencies = ('readers',)
35
36 def parse(self) -> None:
37 """
38 No parsing to do; refurbish the document tree instead.
39 Overrides the inherited method.
40 """
41 self.document = self.input
42 # Create fresh Transformer object, to be populated from Writer
43 # component.
44 self.document.transformer = transforms.Transformer(self.document)
45 # Replace existing settings object with new one.
46 self.document.settings = self.settings
47 # Create fresh Reporter object because it is dependent on
48 # (new) settings.
49 self.document.reporter = utils.new_reporter(
50 self.document.get('source', ''), self.document.settings)