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:
NamedTuple
Represents an exception raised when parsing and reformatting a code block.
- Fields
-
__repr__
()¶ Return a nicely formatted representation string
-
class
RSTReformatter
(filename, config)[source]¶ Bases:
object
Reformat code snippets in a reStructuredText file.
- Parameters
filename (
Union
[str
,Path
,PathLike
]) – The filename to reformat.config (
SnippetFmtConfigDict
) – Thesnippet_fmt
configuration, parsed from a TOML file (or similar).
Attributes:
The
formate
configuration, 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.Match
for 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:
SnippetFmtConfigDict
The
formate
configuration, parsed from a TOML file (or similar).