API Reference
includepy
A Markdown extension that inserts code for Python objects (such as functions and classes).
Classes:
-
ProcessorState–Define an interface for processing Markdown lines.
-
EchoLines–Preserve existing Markdown content.
-
ParseBlock–Parse an IncludePy block and add the specified Python code to the output.
-
IncludePyError–Raised when an error is encountered while attempting to insert the code
-
IncludePyProc–The IncludePy preprocessor.
-
IncludePy–The IncludePy extension class.
Functions:
-
valid_options–Returns the valid option names.
-
default_options–Returns default values for options that have defaults.
-
string_to_bool–Convert a string option into a Boolean value.
-
find_object–Find a named object (e.g., function or class) in a syntax tree.
-
find_docstring–Find a docstring node in an object's syntax tree.
-
selected_lines–Return only selected lines from a code block.
-
makeExtension–Return an instance of the IncludePy extension.
includepy.ProcessorState
Define an interface for processing Markdown lines.
Methods:
-
read_line–Process an input line and return the updated processor state.
read_line
read_line(input_line: str | None, output_lines: list[str]) -> ProcessorState
Process an input line and return the updated processor state.
Parameters:
-
input_line(str | None) –A line of text, or
Noneto indicate the end of the file. -
output_lines(list[str]) –The output Markdown lines, can be mutably updated.
Returns:
-
ProcessorState–The new state of the IncludePy processor.
includepy.EchoLines
includepy.ParseBlock
includepy.IncludePyError
Bases: Exception
Raised when an error is encountered while attempting to insert the code for a Python object.
includepy.IncludePyProc
Bases: Preprocessor
The IncludePy preprocessor.
Methods:
-
run–Process the input Markdown content and include Python source code as
includepy.IncludePy
Bases: Extension
The IncludePy extension class.
Methods:
-
extendMarkdown–Register this extension with a Markdown processor.
includepy.default_options
Returns default values for options that have defaults.
includepy.string_to_bool
Convert a string option into a Boolean value.
includepy.find_object
Find a named object (e.g., function or class) in a syntax tree.
includepy.find_docstring
Find a docstring node in an object's syntax tree.
includepy.selected_lines
Return only selected lines from a code block.
Parameters:
-
input_lines(list[str]) –The input lines of text.
-
only_lines(str) –A string that contains one or more line-range specifiers, separated by commas. Each specifier must have one of the following forms:
nfor thenthinput line,n-for every line from thenthto the end,-nfor every line from the start up to thenth, orn-pfor every line from thenthup to thepth. Note that line numbering begins at1.
Returns: