def whitespacegen(spaces):
    """
    From a certain number of spaces, provide an html entity for non breaking
    spaces in an html document.

    :type spaces: integer
    :param spaces: Number of html space entities to return as string
    :returns: string containing html space entities (&nbsp;) wrapped in
              a html span that properly wraps the whitespace.
    """
    # The average length of a word is 5 letters.. I guess
    words = spaces / 5
    s = "&nbsp;&nbsp;&nbsp;&nbsp; " * int(words)

    #s = " " * spaces
    s = "<span style=\"white-space: pre-wrap;\">" + s + "</span>"
    return s