import re


def expand_refs(comment_line):
    """Adds hrefs to markdown links that do not already have them; e.g.
    expands [Foo] to [Foo](#Foo) but leaves [Foo](https://foo) alone.
    """
    result = comment_line
    result = re.sub(r"\[(\S+)\]([^(])", r"[\1](#\1)\2", result)
    result = re.sub(r"\[(\S+)\]$", r"[\1](#\1)", result)
    return result