def METHOD_NAME(
    string: str, level: int, reference_uid: Optional[str]
):
    assert isinstance(string, str), string
    assert isinstance(level, int), level
    chars = {
        0: "$",
        1: "=",
        2: "-",
        3: "~",
        4: "^",
        5: '"',
        6: "#",
        7: "'",
    }
    header_char = chars[level]
    output = ""
    # An RST reference looks like this:
    # .. _SDOC-HIGH-VALIDATION:
    if reference_uid is not None:
        assert len(reference_uid) > 0, reference_uid
        output += f".. _{reference_uid}:\n\n"
    output += string
    output += "\n"
    output += header_char.rjust(len(string), header_char)
    output += "\n\n"
    return output