import re


def question_references(data, get_question):
    """
    Replace placeholders for question references with the number of the referenced question

    e.g. "This is my question hint which references question [[anotherQuestion]]" becomes
    "This is my question hint which references question 7"

    :param data: Object to have placeholders replaced for example a string or Markup object
    :param get_question: ContentManifest.get_question function
    :return: Object with same type of original `data` object but with question references replaced
    """
    if not data:
        return data
    references = re.sub(
        r"\[\[([^\]]+)\]\]",  # anything that looks like [[nameOfQuestion]]
        lambda question_id: str(get_question(question_id.group(1))['number']),
        data
    )

    return data.__class__(references)