def atx_header_sub(match):
level = len(match.group(<NUM_LIT:1>))<EOL>title = match.group(<NUM_LIT:2>)<EOL>id_class = '<STR_LIT>'<EOL>ids = match.group(<NUM_LIT:3>) if match.group(<NUM_LIT:3>) else '<STR_LIT>'<EOL>id_match = re.search('<STR_LIT>', ids)<EOL>if id_match:<EOL><INDENT>id_class += '<STR_LIT>' + id_match.group(<NUM_LIT:1>) + '<STR_LIT:">'<EOL><DEDENT>classes = '<STR_LIT:U+0020>'.join(re.findall('<STR_LIT>', ids))<EOL>if classes:<EOL><INDENT>id_class += '<STR_LIT>' + classes + '<STR_LIT:">'<EOL><DEDENT>return '<STR_LIT>'.format(level, title, id_class)<EOL>
Substitutes atx headers (headers defined using #'s).