epydoc.colorize

Package epydoc :: Module colorize |
[show private | hide private]
[frames | no frames]

## Module epydoc.colorize

Functions to produce colorized HTML code for various objects. Currently, `colorize` defines functions to colorize regular expressions and doctest blocks.

Function Summary
`string` | ``colorize_doctestblock`(str)` Return the HTML code for a colorized version of a given doctest block.
`string` | ``colorize_re`(regexp)` Return the HTML code for a colorized version of the pattern for the given SRE regular expression.
`string` | ``_colorize_re`(tree, noparen)` Recursively descend the given regexp parse tree to produce the HTML code for a colorized version of the regexp.
`string` | ``_doctest_sub`(match)` This helper function is used by `colorize_doctestblock` to add colorization to matching expressions.

Variable Summary
`str` | `ANY_TAG`: The CSS class for colorizing `"."` in regular expressions.
`str` | `ASSERT_TAG`: The CSS class for colorizing assertions (such as `"(?=abc)"`) in regular expressions.
`str` | `AT_TAG`: The CSS class for colorizing character locations (such as `"^"`) in regular expressions.
`str` | `BRANCH_TAG`: The CSS class for colorizing `"|"` in regular expressions.
`str` | `CATEGORY_TAG`: The CSS class for colorizing character categories (such as `r"\d"`)) in regular expressions.
`str` | `CHOICE_TAG`: The CSS class for colorizing character choice expressions (such as `"[abc]"`) in regular expressions.
`str` | `ESCAPE_TAG`: The CSS class for colorizing escaped characters (such as `r"\("`) in regular expressions.
`str` | `PAREN_TAG`: The CSS class for colorizing parenthases in regular expressions.
`str` | `PLUS_TAG`: The CSS class for colorizing `"+"` and `"+?"` in regular expressions.
`str` | `QMRK_TAG`: The CSS class for colorizing `"?"` and `"??"` in regular expressions.
`str` | `RE_TAG`: The CSS class for colorizing regular expressions.
`str` | `REF_TAG`: The CSS class for colorizing references (such as `r"\1"`) in regular expressions.
`str` | `RNG_TAG`: The CSS class for colorizing repeat ranges (such as `"a{3,8}"`) in regular expressions.
`str` | `STAR_TAG`: The CSS class for colorizing `"*"` and `"*?"` in regular expressions.
`SRE_Pattern` | `_DOCTEST_RE`: The regular expression used by `_doctest_sub` to colorize doctest blocks.
`SRE_Pattern` | `_PROMPT_RE`: The regular expression used to find Python prompts (">>>" and "...") in doctest blocks.

Function Details

### colorize_doctestblock(str) Parameters: `str` - The contents of the doctest block to be colorized. (type=`string`) Returns: The HTML code for a colorized version of a given doctest block. In particular, this identifies spans with the following css classes: py-src: The Python source code. py-prompt: The ">>>" and "..." prompts. py-string: Strings in the Python source code. py-comment: Comments in the Python source code. py-keyword: Keywords in the Python source code. py-output: Python's output (lines without a prompt). The string that is passed to colorize_doctest should already have HTML characters escaped (e.g., `">"` should be encoded as `"&gt;"`). (type=`string`)

### colorize_re(regexp) Parameters: `regexp` - The regular expression to colorize. (type=`SRE_Pattern` or `string`) Returns: The HTML code for a colorized version of the pattern for the given SRE regular expression. If `colorize_re` can't figure out how to colorize the regexp, then it will simply return the (uncolorized) pattern, with `'&'`, `'<'`, and `'>'` escaped as HTML entities. The colorized expression includes spans with the following css classes: re: The entire regular expression. re-char: Special characters (such as `'.'`, `'\('`), character categories (such as `'\w'`), and locations (such as `'\b'`). re-op: Operators (such as `'*'` and `'|'`). re-group: Grouping constructs (such as `'(...)'`). re-ref References (such as `'\1'`) (type=`string`)

### _colorize_re(tree, noparen=0) Recursively descend the given regexp parse tree to produce the HTML code for a colorized version of the regexp. Parameters: `tree` - The regexp parse tree for the regexp that should be colorized. (type=`sre_parse.SubPattern`) `noparen` - If true, then don't include parenthases around the expression in `tree`, even if it contains multiple elements. (type=`boolean`) Returns: The HTML code for a colorized version of `tree` (type=`string`)

### _doctest_sub(match) This helper function is used by `colorize_doctestblock` to add colorization to matching expressions. It is called by `_DOCTEST_RE.sub` with an expression that matches `_DOCTEST_RE`. Returns: The HTML code for the colorized expression. (type=`string`) See Also: `_DOCTEST_RE`

Variable Details

    ### ANY_TAG The CSS class for colorizing `"."` in regular expressions. Type: `str` Value:
        're-char'

    ### ASSERT_TAG The CSS class for colorizing assertions (such as `"(?=abc)"`) in regular expressions. Type: `str` Value:
        're-group'

    ### AT_TAG The CSS class for colorizing character locations (such as `"^"`) in regular expressions. Type: `str` Value:
        're-char'

    ### BRANCH_TAG The CSS class for colorizing `"|"` in regular expressions. Type: `str` Value:
        're-op'

    ### CATEGORY_TAG The CSS class for colorizing character categories (such as `r"\d"`)) in regular expressions. Type: `str` Value:
        're-char'

    ### CHOICE_TAG The CSS class for colorizing character choice expressions (such as `"[abc]"`) in regular expressions. Type: `str` Value:
        're-group'

    ### ESCAPE_TAG The CSS class for colorizing escaped characters (such as `r"\("`) in regular expressions. Type: `str` Value:
        're-char'

    ### PAREN_TAG The CSS class for colorizing parenthases in regular expressions. Type: `str` Value:
        're-group'

    ### PLUS_TAG The CSS class for colorizing `"+"` and `"+?"` in regular expressions. Type: `str` Value:
        're-op'

    ### QMRK_TAG The CSS class for colorizing `"?"` and `"??"` in regular expressions. Type: `str` Value:
        're-op'

    ### RE_TAG The CSS class for colorizing regular expressions. Type: `str` Value:
        're'

    ### REF_TAG The CSS class for colorizing references (such as `r"\1"`) in regular expressions. Type: `str` Value:
        're-ref'

    ### RNG_TAG The CSS class for colorizing repeat ranges (such as `"a{3,8}"`) in regular expressions. Type: `str` Value:
        're-op'

    ### STAR_TAG The CSS class for colorizing `"*"` and `"*?"` in regular expressions. Type: `str` Value:
        're-op'

    ### _DOCTEST_RE The regular expression used by `_doctest_sub` to colorize doctest blocks. Type: `SRE_Pattern` Value:
        (&quot;&quot;&quot;(&quot;&quot;&quot;|.*?((?!&quot;).)&quot;&quot;&qu\
        ot;))|(&quot;(&quot;|.*?((?!&quot;).)&quot;))|('''('''|.*?[^\\']'''))|\
        ('('|.*?[^\\']'))|(#.*?$)|(\bdel\b)|(\bfrom\b)|(\blambda\b)|(\breturn\\
        b)|(\band\b)|(\bor\b)|(\bis\b)|(\bglobal\b)|(\bnot\b)|(\btry\b)|(\bbre\
        ak\b)|(\belse\b)|(\bif\b)|(\belif\b)|(\bwhile\b)|(\bclass\b)|(\bexcept\
        \b)|(\bimport\b)|(\bpass\b)|(\braise\b)|(\bcontinue\b)|(\bfinally\b)|(\
        \bin\b)|(\bprint\b)|(\bdef\b)|(\bfor\b)

    ### _PROMPT_RE The regular expression used to find Python prompts (">>>" and "...") in doctest blocks. Type: `SRE_Pattern` Value:
        (^\s*(&gt;&gt;&gt;|\.\.\.)(\s|$))

Generated by Epydoc 2.1 on Sat Mar 20 17:46:18 2004 | http://epydoc.sf.net