from django import template

import bbcode


def bbcode_img(tag_name, value, options, parent, context):
    if tag_name in options and 'x' in options[tag_name]:
        options['width'], options['height'] = options[tag_name].split('x', 1)
        del options[tag_name]
    attrs = ' '.join([name+'="{}"' for name in options.keys()])
    return ('<img src="{}" '+attrs+' />').format(value, *options.values())


bbcode_parser = bbcode.Parser()
bbcode_parser.add_formatter("img", bbcode_img, replace_links=False)


def bbformat(value):
    return bbcode_parser.format(value)

register = template.Library()
register.filter('bbformat', bbformat)

from django import template

import bbcode


def bbcode_img(tag_name, value, options, parent, context):
    if tag_name in options and 'x' in options[tag_name]:
        options['width'], options['height'] = options[tag_name].split('x', 1)
        del options[tag_name]
    attrs = ' '.join([name+'="{}"' for name in options.keys()])
    return ('<img src="{}" '+attrs+' />').format(value, *options.values())


def bbcode_email(tag_name, value, options, parent, context):
    return '<a href="mailto:{}">{}</a>'.format(value, value)


def bbcode_font(tag_name, value, options, parent, context):
    return '<span style="font-family: {}">{}</span>'.format(options[tag_name], value)

bbcode_parser = bbcode.Parser()
bbcode_parser.add_formatter("img", bbcode_img, replace_links=False)
bbcode_parser.add_formatter("email", bbcode_email)
bbcode_parser.add_formatter("font", bbcode_font)


def bbformat(value):
    return bbcode_parser.format(value)

register = template.Library()
register.filter('bbformat', bbformat)

Add support for email and font bbcode tags.
Add support for email and font bbcode tags.

  from django import template
  
  import bbcode
  
  
  def bbcode_img(tag_name, value, options, parent, context):
      if tag_name in options and 'x' in options[tag_name]:
          options['width'], options['height'] = options[tag_name].split('x', 1)
          del options[tag_name]
      attrs = ' '.join([name+'="{}"' for name in options.keys()])
      return ('<img src="{}" '+attrs+' />').format(value, *options.values())
  
  
+ def bbcode_email(tag_name, value, options, parent, context):
+     return '<a href="mailto:{}">{}</a>'.format(value, value)
+ 
+ 
+ def bbcode_font(tag_name, value, options, parent, context):
+     return '<span style="font-family: {}">{}</span>'.format(options[tag_name], value)
+ 
  bbcode_parser = bbcode.Parser()
  bbcode_parser.add_formatter("img", bbcode_img, replace_links=False)
+ bbcode_parser.add_formatter("email", bbcode_email)
+ bbcode_parser.add_formatter("font", bbcode_font)
  
  
  def bbformat(value):
      return bbcode_parser.format(value)
  
  register = template.Library()
  register.filter('bbformat', bbformat)
  
Add support for email and font bbcode tags.
## Code Before:
from django import template

import bbcode


def bbcode_img(tag_name, value, options, parent, context):
    if tag_name in options and 'x' in options[tag_name]:
        options['width'], options['height'] = options[tag_name].split('x', 1)
        del options[tag_name]
    attrs = ' '.join([name+'="{}"' for name in options.keys()])
    return ('<img src="{}" '+attrs+' />').format(value, *options.values())


bbcode_parser = bbcode.Parser()
bbcode_parser.add_formatter("img", bbcode_img, replace_links=False)


def bbformat(value):
    return bbcode_parser.format(value)

register = template.Library()
register.filter('bbformat', bbformat)

## Instruction:
Add support for email and font bbcode tags.
## Code After:
from django import template

import bbcode


def bbcode_img(tag_name, value, options, parent, context):
    if tag_name in options and 'x' in options[tag_name]:
        options['width'], options['height'] = options[tag_name].split('x', 1)
        del options[tag_name]
    attrs = ' '.join([name+'="{}"' for name in options.keys()])
    return ('<img src="{}" '+attrs+' />').format(value, *options.values())


def bbcode_email(tag_name, value, options, parent, context):
    return '<a href="mailto:{}">{}</a>'.format(value, value)


def bbcode_font(tag_name, value, options, parent, context):
    return '<span style="font-family: {}">{}</span>'.format(options[tag_name], value)

bbcode_parser = bbcode.Parser()
bbcode_parser.add_formatter("img", bbcode_img, replace_links=False)
bbcode_parser.add_formatter("email", bbcode_email)
bbcode_parser.add_formatter("font", bbcode_font)


def bbformat(value):
    return bbcode_parser.format(value)

register = template.Library()
register.filter('bbformat', bbformat)
