more_autodoc.regex
¶
Specialized Documenter for regular expression variables, similar to autodata
.
New in version 1.2.0.
Enable sphinx_toolbox.more_autodoc.regex
by adding the following
to the extensions
variable in your conf.py
:
extensions = [
...
'sphinx_toolbox.more_autodoc.regex',
]
For more information see https://www.sphinx-doc.org/en/master/usage/extensions#third-party-extensions .
Usage¶
-
.. autoregex::
¶ Directive to automatically document a regular expression variable.
The output is based on the
autodata
directive, and takes all of its options except:annotation:
.-
:no-value:
¶ Don’t show the value of the variable.
-
:value:
value (string)¶ Show this instead of the value taken from the Python source code.
-
:no-type:
¶ Don’t show the type of the variable.
-
:flags:
flags (string)¶ Show this instead of the flags taken from the
Pattern
object. This should be correctly formatted for insertion into reStructuredText, such as:py:data:`re.ASCII`
.
Changed in version 2.7.0: The flags
re.DEBUG
andre.VERBOSE
are now hidden as they don’t affect the regex itself.-
-
:regex:
¶ Formats a regular expression with coloured output.
:regex:`^Hello\s+[Ww]orld[.,](Lovely|Horrible) weather, isn't it (.*)?`
^Hello\s+[Ww]orld[.,](Lovely|Horrible) weather, isn't it (.*)?
Changed in version 2.11.0: Now generates coloured output with the LaTeX builder.
API Reference¶
Classes:
|
Specialized Documenter subclass for regex patterns. |
Parser for regular expressions that outputs coloured output. |
|
|
|
|
|
|
Functions:
|
Convert regex flags into “bitwise-or’d” Sphinx xrefs. |
|
No-op that returns the value as a string. |
|
Returns a function that wraps a value in a |
|
Returns a function that wraps a value in a LaTeX |
|
Copy additional stylesheets into the HTML build directory. |
|
-
class
RegexDocumenter
(directive, name, indent='')[source]¶ Bases:
VariableDocumenter
Specialized Documenter subclass for regex patterns.
Methods:
add_content
(more_content[, no_docstring])Add content from docstrings, attribute documentation and the user.
add_directive_header
(sig)Add the directive’s header.
can_document_member
(member, membername, …)Called to see if a member can be documented by this documenter.
-
add_content
(more_content, no_docstring=False)[source]¶ Add content from docstrings, attribute documentation and the user.
-
-
class
RegexParser
[source]¶ Bases:
object
Parser for regular expressions that outputs coloured output.
The formatting is controlled by the following variables:
AT_COLOUR
– Used for e.g.^\A\b\B\Z$
SUBPATTERN_COLOUR
– Used for the parentheses around subpatterns, e.g.(Hello) World
IN_COLOUR
– Used for the square brackets around character sets, e.g.[Hh]ello
REPEAT_COLOUR
– Used for repeats, e.g.A?B+C*D{2,4}E{5}
REPEAT_BRACE_COLOUR
– Used for the braces around numerical repeats.CATEGORY_COLOUR
– Used for categories, e.g.\d\D\s\D\w\W
BRANCH_COLOUR
– Used for branches, e.g.(Lovely|Horrible) Weather
LITERAL_COLOUR
– Used for literal characters.ANY_COLOUR
– Used for the “any” dot.
These are all
Callable
[[Any
],str
].By default no formatting is performed.
Methods:
parse_pattern
(regex)Parse the given regular expression and return the formatted pattern.
-
class
TerminalRegexParser
[source]¶ Bases:
RegexParser
RegexParser
that outputs ANSI coloured output for the terminal.The formatting is controlled by the following functions, which are instances of
consolekit.terminal_colours.Colour
:AT_COLOUR
->YELLOW
– Used for e.g.^\A\b\B\Z$
SUBPATTERN_COLOUR
->LIGHTYELLOW_EX
– Used for the parentheses around subpatterns, e.g.(Hello) World
IN_COLOUR
->LIGHTRED_EX
– Used for the square brackets around character sets, e.g.[Hh]ello
REPEAT_COLOUR
->LIGHTBLUE_EX
– Used for repeats, e.g.A?B+C*D{2,4}E{5}
REPEAT_BRACE_COLOUR
->YELLOW
– Used for the braces around numerical repeats.CATEGORY_COLOUR
->LIGHTYELLOW_EX
– Used for categories, e.g.\d\D\s\D\w\W
BRANCH_COLOUR
->YELLOW
– Used for branches, e.g.(Lovely|Horrible) Weather
LITERAL_COLOUR
->GREEN
– Used for literal characters.ANY_COLOUR
->YELLOW
– Used for the “any” dot.
-
class
HTMLRegexParser
[source]¶ Bases:
RegexParser
RegexParser
that outputs styled HTML.The formatting is controlled by the following functions, which wrap the character in a
span
tag with an appropriate CSS class:AT_COLOUR
->regex_at
– Used for e.g.^\A\b\B\Z$
SUBPATTERN_COLOUR
->regex_subpattern
– Used for the parentheses around subpatterns, e.g.(Hello) World
IN_COLOUR
->regex_in
– Used for the square brackets around character sets, e.g.[Hh]ello
REPEAT_COLOUR
->regex_repeat
– Used for repeats, e.g.A?B+C*D{2,4}E{5}
REPEAT_BRACE_COLOUR
->regex_repeat_brace
– Used for the braces around numerical repeats.CATEGORY_COLOUR
->regex_category
– Used for categories, e.g.\d\D\s\D\w\W
BRANCH_COLOUR
->regex_branch
– Used for branches, e.g.(Lovely|Horrible) Weather
LITERAL_COLOUR
->regex_literal
– Used for literal characters.ANY_COLOUR
->regex_any
– Used for the “any” dot.
Additionally, all
span
tags theregex
class, and the surroundingcode
tag has the following classes:docutils literal notranslate regex
.
-
class
LaTeXRegexParser
[source]¶ Bases:
RegexParser
RegexParser
that outputs styled LaTeX.The formatting is controlled by the following functions, which wrap the character in a LaTeX
textcolor
command for an appropriate colour:AT_COLOUR
->regex_at
– Used for e.g.^\A\b\B\Z$
SUBPATTERN_COLOUR
->regex_subpattern
– Used for the parentheses around subpatterns, e.g.(Hello) World
IN_COLOUR
->regex_in
– Used for the square brackets around character sets, e.g.[Hh]ello
REPEAT_COLOUR
->regex_repeat
– Used for repeats, e.g.A?B+C*D{2,4}E{5}
REPEAT_BRACE_COLOUR
->regex_repeat_brace
– Used for the braces around numerical repeats.CATEGORY_COLOUR
->regex_category
– Used for categories, e.g.\d\D\s\D\w\W
BRANCH_COLOUR
->regex_branch
– Used for branches, e.g.(Lovely|Horrible) Weather
LITERAL_COLOUR
->regex_literal
– Used for literal characters.ANY_COLOUR
->regex_any
– Used for the “any” dot.
New in version 2.11.0.
-
no_formatting
(value)[source]¶ No-op that returns the value as a string.
Used for unformatted output.
- Return type
-
latex_textcolor
(colour_name)[source]¶ Returns a function that wraps a value in a LaTeX
textcolor
command for the given colour.New in version 2.11.0.
-
copy_asset_files
(app, exception=None)[source]¶ Copy additional stylesheets into the HTML build directory.
-
setup
(app)[source]¶ Setup
sphinx_toolbox.more_autodoc.regex
.- Parameters
app (
Sphinx
) – The Sphinx application.- Return type