Given the source of a cell, filter out all cell and line magics.

def strip_magics(source):
    """
    Given the source of a cell, filter out all cell and line magics.
    """
    filtered=[]
    for line in source.splitlines():
        if not line.startswith('%') or line.startswith('%%'):
            filtered.append(line)
    return '\n'.join(filtered)