def formatString(para, pageWidth):
    """Format a string to have line lengths < pageWidth"""

    para = " ".join(para.split("\n")).lstrip()

    outStr = []
    outLine = ""
    for word in para.split():
        if outLine and len(outLine) + len(word) + 1 > pageWidth:
            outStr.append(outLine)
            outLine = ""

        if outLine:
            outLine += " "
        outLine += word

    if outLine:
        outStr.append(outLine)

    return "\n".join(outStr)