first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
|
@ -0,0 +1,113 @@
|
|||
# $Id: __init__.py 9258 2022-11-21 14:51:43Z milde $
|
||||
# Authors: David Goodger <goodger@python.org>; Ueli Schlaepfer
|
||||
# Copyright: This module has been placed in the public domain.
|
||||
|
||||
"""
|
||||
This package contains Docutils Reader modules.
|
||||
"""
|
||||
|
||||
__docformat__ = 'reStructuredText'
|
||||
|
||||
from importlib import import_module
|
||||
|
||||
from docutils import utils, parsers, Component
|
||||
from docutils.transforms import universal
|
||||
|
||||
|
||||
class Reader(Component):
|
||||
|
||||
"""
|
||||
Abstract base class for docutils Readers.
|
||||
|
||||
Each reader module or package must export a subclass also called 'Reader'.
|
||||
|
||||
The two steps of a Reader's responsibility are to read data from the
|
||||
source Input object and parse the data with the Parser object.
|
||||
Call `read()` to process a document.
|
||||
"""
|
||||
|
||||
component_type = 'reader'
|
||||
config_section = 'readers'
|
||||
|
||||
def get_transforms(self):
|
||||
return super().get_transforms() + [universal.Decorations,
|
||||
universal.ExposeInternals,
|
||||
universal.StripComments]
|
||||
|
||||
def __init__(self, parser=None, parser_name=None):
|
||||
"""
|
||||
Initialize the Reader instance.
|
||||
|
||||
Several instance attributes are defined with dummy initial values.
|
||||
Subclasses may use these attributes as they wish.
|
||||
"""
|
||||
|
||||
self.parser = parser
|
||||
"""A `parsers.Parser` instance shared by all doctrees. May be left
|
||||
unspecified if the document source determines the parser."""
|
||||
|
||||
if parser is None and parser_name:
|
||||
self.set_parser(parser_name)
|
||||
|
||||
self.source = None
|
||||
"""`docutils.io` IO object, source of input data."""
|
||||
|
||||
self.input = None
|
||||
"""Raw text input; either a single string or, for more complex cases,
|
||||
a collection of strings."""
|
||||
|
||||
def set_parser(self, parser_name):
|
||||
"""Set `self.parser` by name."""
|
||||
parser_class = parsers.get_parser_class(parser_name)
|
||||
self.parser = parser_class()
|
||||
|
||||
def read(self, source, parser, settings):
|
||||
self.source = source
|
||||
if not self.parser:
|
||||
self.parser = parser
|
||||
self.settings = settings
|
||||
self.input = self.source.read()
|
||||
self.parse()
|
||||
return self.document
|
||||
|
||||
def parse(self):
|
||||
"""Parse `self.input` into a document tree."""
|
||||
self.document = document = self.new_document()
|
||||
self.parser.parse(self.input, document)
|
||||
document.current_source = document.current_line = None
|
||||
|
||||
def new_document(self):
|
||||
"""Create and return a new empty document tree (root node)."""
|
||||
return utils.new_document(self.source.source_path, self.settings)
|
||||
|
||||
|
||||
class ReReader(Reader):
|
||||
|
||||
"""
|
||||
A reader which rereads an existing document tree (e.g. a
|
||||
deserializer).
|
||||
|
||||
Often used in conjunction with `writers.UnfilteredWriter`.
|
||||
"""
|
||||
|
||||
def get_transforms(self):
|
||||
# Do not add any transforms. They have already been applied
|
||||
# by the reader which originally created the document.
|
||||
return Component.get_transforms(self)
|
||||
|
||||
|
||||
_reader_aliases = {}
|
||||
|
||||
|
||||
def get_reader_class(reader_name):
|
||||
"""Return the Reader class from the `reader_name` module."""
|
||||
name = reader_name.lower()
|
||||
name = _reader_aliases.get(name, name)
|
||||
try:
|
||||
module = import_module('docutils.readers.'+name)
|
||||
except ImportError:
|
||||
try:
|
||||
module = import_module(name)
|
||||
except ImportError as err:
|
||||
raise ImportError(f'Reader "{reader_name}" not found. {err}')
|
||||
return module.Reader
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,46 @@
|
|||
# $Id: doctree.py 4564 2006-05-21 20:44:42Z wiemann $
|
||||
# Author: Martin Blais <blais@furius.ca>
|
||||
# Copyright: This module has been placed in the public domain.
|
||||
|
||||
"""Reader for existing document trees."""
|
||||
|
||||
from docutils import readers, utils, transforms
|
||||
|
||||
|
||||
class Reader(readers.ReReader):
|
||||
|
||||
"""
|
||||
Adapt the Reader API for an existing document tree.
|
||||
|
||||
The existing document tree must be passed as the ``source`` parameter to
|
||||
the `docutils.core.Publisher` initializer, wrapped in a
|
||||
`docutils.io.DocTreeInput` object::
|
||||
|
||||
pub = docutils.core.Publisher(
|
||||
..., source=docutils.io.DocTreeInput(document), ...)
|
||||
|
||||
The original document settings are overridden; if you want to use the
|
||||
settings of the original document, pass ``settings=document.settings`` to
|
||||
the Publisher call above.
|
||||
"""
|
||||
|
||||
supported = ('doctree',)
|
||||
|
||||
config_section = 'doctree reader'
|
||||
config_section_dependencies = ('readers',)
|
||||
|
||||
def parse(self):
|
||||
"""
|
||||
No parsing to do; refurbish the document tree instead.
|
||||
Overrides the inherited method.
|
||||
"""
|
||||
self.document = self.input
|
||||
# Create fresh Transformer object, to be populated from Writer
|
||||
# component.
|
||||
self.document.transformer = transforms.Transformer(self.document)
|
||||
# Replace existing settings object with new one.
|
||||
self.document.settings = self.settings
|
||||
# Create fresh Reporter object because it is dependent on
|
||||
# (new) settings.
|
||||
self.document.reporter = utils.new_reporter(
|
||||
self.document.get('source', ''), self.document.settings)
|
|
@ -0,0 +1,48 @@
|
|||
# $Id: pep.py 9258 2022-11-21 14:51:43Z milde $
|
||||
# Author: David Goodger <goodger@python.org>
|
||||
# Copyright: This module has been placed in the public domain.
|
||||
|
||||
"""
|
||||
Python Enhancement Proposal (PEP) Reader.
|
||||
"""
|
||||
|
||||
__docformat__ = 'reStructuredText'
|
||||
|
||||
|
||||
from docutils.readers import standalone
|
||||
from docutils.transforms import peps, frontmatter
|
||||
from docutils.parsers import rst
|
||||
|
||||
|
||||
class Reader(standalone.Reader):
|
||||
|
||||
supported = ('pep',)
|
||||
"""Contexts this reader supports."""
|
||||
|
||||
settings_spec = (
|
||||
'PEP Reader Option Defaults',
|
||||
'The --pep-references and --rfc-references options (for the '
|
||||
'reStructuredText parser) are on by default.',
|
||||
())
|
||||
|
||||
config_section = 'pep reader'
|
||||
config_section_dependencies = ('readers', 'standalone reader')
|
||||
|
||||
def get_transforms(self):
|
||||
transforms = super().get_transforms()
|
||||
# We have PEP-specific frontmatter handling.
|
||||
transforms.remove(frontmatter.DocTitle)
|
||||
transforms.remove(frontmatter.SectionSubTitle)
|
||||
transforms.remove(frontmatter.DocInfo)
|
||||
transforms.extend([peps.Headers, peps.Contents, peps.TargetNotes])
|
||||
return transforms
|
||||
|
||||
settings_default_overrides = {'pep_references': 1, 'rfc_references': 1}
|
||||
|
||||
inliner_class = rst.states.Inliner
|
||||
|
||||
def __init__(self, parser=None, parser_name=None):
|
||||
"""`parser` should be ``None``."""
|
||||
if parser is None:
|
||||
parser = rst.Parser(rfc2822=True, inliner=self.inliner_class())
|
||||
standalone.Reader.__init__(self, parser, '')
|
|
@ -0,0 +1,65 @@
|
|||
# $Id: standalone.py 9539 2024-02-17 10:36:51Z milde $
|
||||
# Author: David Goodger <goodger@python.org>
|
||||
# Copyright: This module has been placed in the public domain.
|
||||
|
||||
"""
|
||||
Standalone file Reader for the reStructuredText markup syntax.
|
||||
"""
|
||||
|
||||
__docformat__ = 'reStructuredText'
|
||||
|
||||
|
||||
from docutils import frontend, readers
|
||||
from docutils.transforms import frontmatter, references, misc
|
||||
|
||||
|
||||
class Reader(readers.Reader):
|
||||
|
||||
supported = ('standalone',)
|
||||
"""Contexts this reader supports."""
|
||||
|
||||
document = None
|
||||
"""A single document tree."""
|
||||
|
||||
settings_spec = (
|
||||
'Standalone Reader Options',
|
||||
None,
|
||||
(('Disable the promotion of a lone top-level section title to '
|
||||
'document title (and subsequent section title to document '
|
||||
'subtitle promotion; enabled by default).',
|
||||
['--no-doc-title'],
|
||||
{'dest': 'doctitle_xform', 'action': 'store_false',
|
||||
'default': True, 'validator': frontend.validate_boolean}),
|
||||
('Disable the bibliographic field list transform (enabled by '
|
||||
'default).',
|
||||
['--no-doc-info'],
|
||||
{'dest': 'docinfo_xform', 'action': 'store_false',
|
||||
'default': True, 'validator': frontend.validate_boolean}),
|
||||
('Activate the promotion of lone subsection titles to '
|
||||
'section subtitles (disabled by default).',
|
||||
['--section-subtitles'],
|
||||
{'dest': 'sectsubtitle_xform', 'action': 'store_true',
|
||||
'default': False, 'validator': frontend.validate_boolean}),
|
||||
('Deactivate the promotion of lone subsection titles.',
|
||||
['--no-section-subtitles'],
|
||||
{'dest': 'sectsubtitle_xform', 'action': 'store_false'}),
|
||||
))
|
||||
|
||||
config_section = 'standalone reader'
|
||||
config_section_dependencies = ('readers',)
|
||||
|
||||
def get_transforms(self):
|
||||
return super().get_transforms() + [
|
||||
references.Substitutions,
|
||||
references.PropagateTargets,
|
||||
frontmatter.DocTitle,
|
||||
frontmatter.SectionSubTitle,
|
||||
frontmatter.DocInfo,
|
||||
references.AnonymousHyperlinks,
|
||||
references.IndirectHyperlinks,
|
||||
references.Footnotes,
|
||||
references.ExternalTargets,
|
||||
references.InternalTargets,
|
||||
references.DanglingReferences,
|
||||
misc.Transitions,
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue