def expand_db_html(html, for_editor=False):
 def replace_a_tag(m):
  attrs = extract_attrs(m.group(1))
  if (u'linktype' not in attrs):
   return m.group(0)
  handler = get_link_handler(attrs[u'linktype'])
  return handler.expand_db_attributes(attrs, for_editor)
 def replace_embed_tag(m):
  attrs = extract_attrs(m.group(1))
  handler = get_embed_handler(attrs[u'embedtype'])
  return handler.expand_db_attributes(attrs, for_editor)
 html = FIND_A_TAG.sub(replace_a_tag, html)
 html = FIND_EMBED_TAG.sub(replace_embed_tag, html)
 return html

def expand_db_html ( html , for_editor = False ) : def replace_a_tag ( m ) : attrs = extract_attrs ( m . group ( 1 ) ) if ( u'linktype' not in attrs ) : return m . group ( 0 ) handler = get_link_handler ( attrs [ u'linktype' ] ) return handler . expand_db_attributes ( attrs , for_editor ) def replace_embed_tag ( m ) : attrs = extract_attrs ( m . group ( 1 ) ) handler = get_embed_handler ( attrs [ u'embedtype' ] ) return handler . expand_db_attributes ( attrs , for_editor ) html = FIND_A_TAG . sub ( replace_a_tag , html ) html = FIND_EMBED_TAG . sub ( replace_embed_tag , html ) return html
expand database-representation html into proper html usable in either templates or the rich text editor .