from django import template
import re
from django.utils.safestring import mark_safe

register = template.Library()


@register.filter
def highlight(text, word):
	pattern = re.compile('(%s)' % word, re.IGNORECASE)
	result = pattern.sub(r'<b>\1</b>',text)
	return mark_safe(result)

@register.simple_tag
def random_int(a, b=None):
	if b is None:
		a, b = 0, a
	return random.randint(a, b)
