from django import template
import re
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from django.urls import reverse
from members.models import Member, Job

register = template.Library()


@register.filter(is_safe=True)
@stringfilter
def tags_to_url(value):
    # return "Tag to url: %s" % value
    return mark_safe(
        re.sub(r"\#([\d\w-]+)", r'<a href="/posts/t/\g<1>">#\g<1></a>', value)
    )
