import re


def replace_image_link(target_str):
    """
    Replace the shorthand of an image link { image.jpg } with the full link {{ img_tag("image.jpg") | safe }}
    :param target_str: String with images in it to be edited
    :return: string with images formatted as {{ img_tag("image.jpg") | safe }}
    """
    # Find all image links as {image.jpg} or { image.jpg } etc...
    image_list = re.findall(r'{(\s*\w+\.\w+\s*)}', target_str)
    # Drop the first and last characters to get citation numbers.
    img_name_list = [cit.strip() for cit in image_list]
    for idx, img in enumerate(image_list):
        # Replace the citation shorthand with the proper markdown.
        target_str = target_str.replace(img, f'{{ img_tag("{img_name_list[idx]}") | safe }}')
    return target_str