def delf(text):
    """remove carriage-returns and single line-feeds from text
       - leaves double line-feeds (paragraph breaks)
       - also removes trailing spaces
       - source must be a string
    """
    # remove trailing spaces
    lines=[line.rstrip() for line in text.split('\n')]
    cleantext='\n'.join(lines)
    # remove carriage returns and single line feeds
    return cleantext.replace('\r','').replace('\n\n','\r').replace('\n',' ').replace('\r','\n\n')