A text-filter helper, used in ``markdown_thumbnails``-filter and ``html_thumbnails``-filter.
    It can be used to build custom thumbnail text-filters.

    :param regex_base: A string with a regex that contains ``%(captions)s`` and ``%(image)s`` where
                       the caption and image should be.
    :param value: String of text in which the source URLs can be found.
    :return: A string ready to be put in a template.

def text_filter(regex_base, value):
    """
    A text-filter helper, used in ``markdown_thumbnails``-filter and ``html_thumbnails``-filter.
    It can be used to build custom thumbnail text-filters.

    :param regex_base: A string with a regex that contains ``%(captions)s`` and ``%(image)s`` where
                       the caption and image should be.
    :param value: String of text in which the source URLs can be found.
    :return: A string ready to be put in a template.
    """
    from thumbnails import get_thumbnail
    regex = regex_base % {
        'caption': '[a-zA-Z0-9\.\,:;/_ \(\)\-\!\?\"]+',
        'image': '[a-zA-Z0-9\.:/_\-\% ]+'
    }
    images = re.findall(regex, value)

    for i in images:
        image_url = i[1]
        image = get_thumbnail(
            image_url,
            **settings.THUMBNAIL_FILTER_OPTIONS
        )
        value = value.replace(i[1], image.url)

    return value