def underline(line, underline='~'):
    """Return an underline string for ``line``.
    
    Intended for use with level 3 and lower headings.
    
    Note that the default for ``underline`` assumes that the level
    1 and 2 underlines are the standard ``=`` and ``-``. You can
    pass a different underline character to this function if needed.
    """
    
    if line.endswith('\n'):
        line = line[:-1]
    return "{}\n".format(underline * len(line))