def METHOD_NAME(filepath, heading, anchor):
    if anchor is None:
        # The replace(' -- ', '') is needed because AsciiDoc transforms ' -- ' to '&#8201;&#8212;&#8201;' (narrow-space, em-dash, narrow-space) which then collapses down to '' when calculating the anchor
        anchor = re.sub(r'\-+', '-', re.sub(r'[^-\w]', '', heading.lower().replace(' -- ', '').replace(' ', '-').replace('.', '-')))
    if filepath not in file_headings:
        file_headings[filepath] = set()
    proposed_anchor = anchor
    num = 1 # this isn't a logic bug, the first duplicate anchor gets suffixed with "-2"
    while proposed_anchor in file_headings[filepath]:
        num += 1
        proposed_anchor = '{}-{}'.format(anchor, num)
    file_headings[filepath].add(proposed_anchor)
    return proposed_anchor