snippet_fmt¶
Format and validate code snippets in reStructuredText files.
Classes:
|
Represents an exception raised when parsing and reformatting a code block. |
|
Reformat code snippets in a reStructuredText file. |
Functions:
|
Reformat the given reStructuredText file, and show the diff if changes were made. |
-
namedtuple
CodeBlockError(offset, exc)[source]¶ Bases:
NamedTupleRepresents an exception raised when parsing and reformatting a code block.
- Fields
-
__repr__()¶ Return a nicely formatted representation string
-
class
RSTReformatter(filename, config)[source]¶ Bases:
objectReformat code snippets in a reStructuredText file.
- Parameters
filename (
Union[str,Path,PathLike]) – The filename to reformat.config (
SnippetFmtConfigDict) – Thesnippet_fmtconfiguration, parsed from a TOML file (or similar).
Attributes:
The
formateconfiguration, parsed from a TOML file (or similar).The filename being reformatted, as a POSIX-style path.
The filename being reformatted.
Methods:
get_diff()Returns the diff between the original and reformatted file content.
Load custom formatters defined via entry points.
process_match(match)Process a
re.Matchfor a single code block.run()Run the reformatter.
to_file()Write the reformatted source to the original file.
Return the reformatted file as a string.
-
config¶ Type:
SnippetFmtConfigDictThe
formateconfiguration, parsed from a TOML file (or similar).