code: def xep_role(typ, rawtext, text, lineno, inliner,
               options={}, content=[]):
      
      env = inliner.document.settings.env
      if not typ:
          typ = env.config.default_role
      else:
          typ = typ.lower()
      has_explicit_title, title, target = split_explicit_title(text)
      title = utils.unescape(title)
      target = utils.unescape(target)
      targetid = 'index-%s' % env.new_serialno('index')
      anchor = ''
      anchorindex = target.find('#')
      if anchorindex > 0:
          target, anchor = target[:anchorindex], target[anchorindex:]
      try:
          xepnum = int(target)
      except ValueError:
          msg = inliner.reporter.error('invalid XEP number %s' % target,
                                       line=lineno)
          prb = inliner.problematic(rawtext, rawtext, msg)
          return [prb], [msg]
      target = "{:04d}".format(xepnum)
      if not has_explicit_title:
          title = "XEP-" + target
      indexnode = addnodes.index()
      targetnode = nodes.target('', '', ids=[targetid])
      inliner.document.note_explicit_target(targetnode)
      indexnode['entries'] = [
          ('single', _('XMPP Extension Protocols (XEPs); XEP %s') % target,
           targetid, '')]
      ref = inliner.document.settings.xep_base_url + 'xep-%04d.html' % xepnum
      rn = nodes.reference(title, title, internal=False, refuri=ref+anchor,
                           classes=[typ])
      return [indexnode, targetnode, rn], []
docs: Role for PEP/RFC references that generate an index entry.