| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
""" |
| 6 |
Standalone file Reader for the reStructuredText markup syntax. |
| 7 |
""" |
| 8 |
|
| 9 |
from __future__ import annotations |
| 10 |
|
| 11 |
__docformat__ = 'reStructuredText' |
| 12 |
|
| 13 |
from docutils import frontend, readers |
| 14 |
from docutils.transforms import frontmatter, references, misc |
| 15 |
|
| 16 |
TYPE_CHECKING = False |
| 17 |
if TYPE_CHECKING: |
| 18 |
from docutils.transforms import Transform |
| 19 |
|
| 20 |
|
| 21 |
class Reader(readers.Reader): |
| 22 |
|
| 23 |
supported = ('standalone',) |
| 24 |
"""Contexts this reader supports.""" |
| 25 |
|
| 26 |
document = None |
| 27 |
"""A single document tree.""" |
| 28 |
|
| 29 |
settings_spec = ( |
| 30 |
'Standalone Reader Options', |
| 31 |
None, |
| 32 |
(('Disable the promotion of a lone top-level section title to ' |
| 33 |
'document title (and subsequent section title to document ' |
| 34 |
'subtitle promotion; enabled by default).', |
| 35 |
['--no-doc-title'], |
| 36 |
{'dest': 'doctitle_xform', 'action': 'store_false', |
| 37 |
'default': True, 'validator': frontend.validate_boolean}), |
| 38 |
('Disable the bibliographic field list transform (enabled by ' |
| 39 |
'default).', |
| 40 |
['--no-doc-info'], |
| 41 |
{'dest': 'docinfo_xform', 'action': 'store_false', |
| 42 |
'default': True, 'validator': frontend.validate_boolean}), |
| 43 |
('Activate the promotion of lone subsection titles to ' |
| 44 |
'section subtitles (disabled by default).', |
| 45 |
['--section-subtitles'], |
| 46 |
{'dest': 'sectsubtitle_xform', 'action': 'store_true', |
| 47 |
'default': False, 'validator': frontend.validate_boolean}), |
| 48 |
('Deactivate the promotion of lone subsection titles.', |
| 49 |
['--no-section-subtitles'], |
| 50 |
{'dest': 'sectsubtitle_xform', 'action': 'store_false'}), |
| 51 |
)) |
| 52 |
|
| 53 |
config_section = 'standalone reader' |
| 54 |
config_section_dependencies = ('readers',) |
| 55 |
|
| 56 |
def get_transforms(self) -> list[type[Transform]]: |
| 57 |
return super().get_transforms() + [ |
| 58 |
references.Substitutions, |
| 59 |
references.SectionIDs, |
| 60 |
references.PropagateTargets, |
| 61 |
frontmatter.DocTitle, |
| 62 |
frontmatter.SectionSubTitle, |
| 63 |
frontmatter.DocInfo, |
| 64 |
references.AnonymousHyperlinks, |
| 65 |
references.IndirectHyperlinks, |
| 66 |
references.Footnotes, |
| 67 |
references.ExternalTargets, |
| 68 |
references.InternalTargets, |
| 69 |
references.DanglingReferences, |
| 70 |
misc.Transitions, |
| 71 |
] |