def _filter_markdown(source, filters):
    """Only keep some Markdown headers from a Markdown string."""
    lines = source.splitlines()
    # Filters is a list of 'hN' strings where 1 <= N <= 6.
    headers = [_replace_header_filter(filter) for filter in filters]
    lines = [line for line in lines if line.startswith(tuple(headers))]
    return '\n'.join(lines)
Only keep some Markdown headers from a Markdown string.
ipymd/lib/markdown.py