import re


def condense_whitespace(docstring: str) -> str:
    """Collapses excess whitespace in a string.

    This will reduce any spaces in excess of 1 down to a single space and will strip excess leading spaces.  It will
    also collapse any newlines in excess of 2 down to 2 newlines (so single returns and blank lines are preserved,
    but multiple blank lines will be collapsed into a single blank line).

    Args:
        docstring: the docstring that needs to have excess whitespace condensed.

    Returns:
        A copy of the provided docstring with the excess whitespace condensed.
    """
    docstring = re.sub("  *", " ", docstring, flags=re.M)
    docstring = re.sub("^ ", "", docstring, flags=re.M)
    docstring = re.sub("\n\n\n+", "\n\n", docstring, flags=re.M)
    return docstring