module documentation

Syntax highlighting for blocks of Python code.
Function colorize​_codeblock Colorize a string containing only Python code. This method differs from colorize_doctest in that it will not search for doctest prompts when deciding how to colorize the string.
Function colorize​_codeblock​_body Undocumented
Function colorize​_doctest Perform syntax highlighting on the given doctest string, and return the resulting HTML code.
Function colorize​_doctest​_body Undocumented
Function subfunc Undocumented
Constant DEFINE​_FUNC​_RE Undocumented
Constant DOCTEST​_DIRECTIVE​_RE Undocumented
Constant DOCTEST​_EXAMPLE​_RE Undocumented
Constant DOCTEST​_RE Undocumented
Constant EXCEPT​_RE Undocumented
Constant PROMPT2​_RE Undocumented
Constant PROMPT​_RE Undocumented
Constant ​_BUILTIN​_GRP Undocumented
Constant ​_BUILTINS Undocumented
Constant ​_COMMENT​_GRP Undocumented
Constant ​_DEFINE​_GRP Undocumented
Constant ​_KEYWORD​_GRP Undocumented
Constant ​_KEYWORDS Undocumented
Constant ​_PROMPT1​_GRP Undocumented
Constant ​_PROMPT2​_GRP Undocumented
Constant ​_STRING​_GRP Undocumented
def colorize_codeblock(s):

Colorize a string containing only Python code. This method differs from colorize_doctest in that it will not search for doctest prompts when deciding how to colorize the string.

This code consists of a <pre> block with class=py-doctest. Syntax highlighting is performed using the following CSS classes:

  • py-keyword -- a Python keyword (for, if, etc.)
  • py-builtin -- a Python builtin name (abs, dir, etc.)
  • py-string -- a string literal
  • py-comment -- a comment
  • py-except -- an exception traceback (up to the next >>>)
  • py-output -- the output from a doctest block.
  • py-defname -- the name of a function or class defined by a def or class statement.
Parameters
s:strUndocumented
Returns
TagUndocumented
def colorize_codeblock_body(s):

Undocumented

Parameters
s:strUndocumented
Returns
Iterator[Union[Tag, str]]Undocumented
def colorize_doctest(s):

Perform syntax highlighting on the given doctest string, and return the resulting HTML code.

This code consists of a <pre> block with class=py-doctest. Syntax highlighting is performed using the following CSS classes:

  • py-prompt -- the Python PS1 prompt (>>>)
  • py-more -- the Python PS2 prompt (...)
  • the CSS classes output by colorize_codeblock
Parameters
s:strUndocumented
Returns
TagUndocumented
def colorize_doctest_body(s):

Undocumented

Parameters
s:strUndocumented
Returns
Iterator[Union[str, Tag]]Undocumented
def subfunc(match):

Undocumented

Parameters
match:Match[str]Undocumented
Returns
Iterator[Union[Tag, str]]Undocumented
DEFINE_FUNC_RE =

Undocumented

Value
re.compile(r'(?P<def>\w+)(?P<space>\s+)(?P<name>\w+)')
DOCTEST_DIRECTIVE_RE =

Undocumented

Value
re.compile(r'#[ \t]*doctest:.*')
DOCTEST_EXAMPLE_RE =

Undocumented

Value
re.compile('''
    # Source consists of a PS1 line followed by zero or more PS2 lines.
    (?P<source>
        (?:^(?P<indent> [ ]*) >>>    .*)    # PS1 line
        (?:\\n           [ ]*  \\.\\.\\. .*)*   # PS2 lines
        \\n?)
    # Want consists of any non-blank lines that do not start with PS1.
...
DOCTEST_RE =

Undocumented

Value
re.compile(f"""((?P<STRING>{_STRING_GRP})|(?P<COMMENT>{_COMMENT_GRP})|(?P<DEFINE
>{_DEFINE_GRP})|(?P<KEYWORD>{_KEYWORD_GRP})|(?P<BUILTIN>{_BUILTIN_GRP})|(?P<PROM
PT1>{_PROMPT1_GRP})|(?P<PROMPT2>{_PROMPT2_GRP})|(?P<EOS>\\Z))""",
           re.MULTILINE|re.DOTALL)
EXCEPT_RE =

Undocumented

Value
re.compile(r'^[ \t]*Traceback \(most recent call last\):.*',
           re.DOTALL|re.MULTILINE)
PROMPT2_RE =

Undocumented

Value
re.compile(f"""({_PROMPT2_GRP})""", re.MULTILINE|re.DOTALL)
PROMPT_RE =

Undocumented

Value
re.compile(f"""({_PROMPT1_GRP}|{_PROMPT2_GRP})""", re.MULTILINE|re.DOTALL)
_BUILTIN_GRP =

Undocumented

Value
'(?<!\\.)(?:%s)'%"""|""".join((f'\\b{_BI}\\b' for _BI in _BUILTINS))
_BUILTINS =

Undocumented

Value
[_BI for _BI in dir(builtins) if not _BI.startswith('__')]
_COMMENT_GRP: str =

Undocumented

Value
'(#.*?$)'
_DEFINE_GRP: str =

Undocumented

Value
'\\b(?:def|class)[ \\t]+\\w+'
_KEYWORD_GRP =

Undocumented

Value
"""|""".join((f'\\b{_KW}\\b' for _KW in _KEYWORDS))
_KEYWORDS: list[str] =

Undocumented

Value
['and',
 'as',
 'assert',
 'async',
 'await',
 'break',
 'class',
...
_PROMPT1_GRP: str =

Undocumented

Value
'^[ \\t]*>>>(?:[ \\t]|$)'
_PROMPT2_GRP: str =

Undocumented

Value
'^[ \\t]*\\.\\.\\.(?:[ \\t]|$)'
_STRING_GRP =

Undocumented

Value
"""|""".join(['("""("""|.*?((?!").)"""))',
              '("("|.*?((?!").)"))',
              '(\'\'\'(\'\'\'|.*?[^\\\\\']\'\'\'))',
              '(\'(\'|.*?[^\\\\\']\'))'])