code: def serialize_link(ctx, document, elem, root):
      
  
      _a = etree.SubElement(root, 'a')
  
      for el in elem.elements:
          _ser = ctx.get_serializer(el)
  
          if _ser:
              _td = _ser(ctx, document, el, _a)
          else:
              if isinstance(el, doc.Text):
                  children = list(_a)
  
                  if len(children) == 0:
                      _text = _a.text or u''
  
                      _a.text = u'{}{}'.format(_text, el.value())
                  else:
                      _text = children[-1].tail or u''
  
                      children[-1].tail = u'{}{}'.format(_text, el.value())
     
      if elem.rid in document.relationships[ctx.options['relationship']]:
          _a.set('href', document.relationships[ctx.options['relationship']][elem.rid].get('target', ''))
  
      fire_hooks(ctx, document, elem, _a, ctx.get_hook('a'))
  
      return root
docs: Serilaze link element.
  
      This works only for external links at the moment.