import re


def github_sanitize_id(x):
    """
    Sanitize an ID by near-GitHub standards (see toc_filter.rb in
    https://github.com/jch/html-pipeline):
     * remove punctuation besides hyphens and underscores
     * change spaces to hyphens
     * downcase
    Note that it doesn't:
     * add unique suffixes (-1, -2, etc.)
    """
    return re.sub(r'[^-\w ]', '', x.lower(), re.U).replace(' ', '-')