| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 43 |
|
| 44 |
self.document.transformer = transforms.Transformer(self.document) |
| 45 |
|
| 46 |
self.document.settings = self.settings |
| 47 |
|
| 48 |
|
| 49 |
self.document.reporter = utils.new_reporter( |
| 50 |
self.document.get('source', ''), self.document.settings) |