from django import template
import re

register = template.Library()

def make_really_big(value, m):
    """
    >>>make_really_big("40px", 4)
    >>>160px
    """
    v = str(value).strip()
    if v[-2:] == 'px':
      no = int(value.replace("px", "")) * m
      return str(int(round(no))) + "px"
    else:
      return value

def parse_html(value, m):
  """
  >>>parse_html("foo is 20px", 4)
  >>>"foo is 80px"
  """
  p = "font\-size:[\s]?[0-9][0-9]?px"
  matches = re.findall(p, value)
  for match in matches:
#    reg = r'font-size:[\s?]
    s = match.replace("font-size:", "")
    val = int(s.strip().replace("px", ""))
    new_val = int(round(val * m))
    r = "font-size: " + str(new_val) + "px"
    value = value.replace(match, r)    
  return value

register.filter('make_really_big', make_really_big)
register.filter("parse_html", parse_html)
