import re


def heading_to_filename(heading):
    """This function replaces whitespace, ., `, and () with hyphens. It then
    lowercases the heading string and adds a markdown extension (.md)
    """
    filename = heading.lower()

    # Replace bad chars
    filename = re.sub("[\\s`\\.\\(\\)]+", "-", filename)

    # Remove leading hyphens
    filename = re.sub("^[\\-]", "", filename)

    return "%s.md" % filename