old_contents: import dxr.plugins
  import re
  import sys
  
  
  bugFinder = re.compile("(?i)bug\s+#?([0-9]+)")  # also used in hg plugin
  
  # Global variables
  bugzilla  = None
  name      = None
  
  # Load global variables
  def load(tree, conn):
      global bugzilla
      # Get bugzilla link
      if hasattr(tree, 'plugin_buglink_bugzilla'):
          bugzilla = tree.plugin_buglink_bugzilla
      else:
          print >> sys.stderr, "buglink plugin needs plugin_buglink_bugzilla configuration key"
          sys.exit(1)
      # Get bug tracker name
      if hasattr(tree, 'plugin_buglink_name'):
          name = tree.plugin_buglink_name
      else:
          print >> sys.stderr, "buglink plugin needs plugin_buglink_name configuration key"
          sys.exit(1)
  
  class BugLinkHtmlifier(object):
      def __init__(self, text):
          self.text = text
  
      def refs(self):
          for m in bugFinder.finditer(self.text):
              bug = m.group(1)
              yield m.start(0), m.end(0), ([{
                  'text':     "Lookup #%s" % bug,
                  'title':    "Find this bug number at %s" % name,
                  'href':     bugzilla % bug,
                  'icon':     'buglink'
              }], '')
  
      def regions(self):
          return []
  
      def annotations(self):
          return []
  
      def links(self):
          return []
  
  def htmlify(path, text):
      return BugLinkHtmlifier(text)
  
  __all__ = dxr.plugins.htmlifier_exports()
  
new_contents: import re
  import sys
  
  import dxr.plugins
  
  
  # Global variables
  url       = None
  name      = None
  bug_finder = None
  
  
  # Load global variables
  def load(tree, conn):
      global url, name, bug_finder
  
      # Get bug tracker name
      if hasattr(tree, 'plugin_buglink_name'):
          name = tree.plugin_buglink_name
      else:
          print >> sys.stderr, 'buglink plugin needs plugin_buglink_name configuration key'
          sys.exit(1)
  
      # Get link
      # The plugin_buglink_bugzilla option behaves identically but is deprecated.
      url = getattr(tree, 'plugin_buglink_url',
                          getattr(tree, 'plugin_buglink_bugzilla', None))
      if url is None:
          print >> sys.stderr, 'buglink plugin needs plugin_buglink_url configuration key'
          sys.exit(1)
  
      # Get bug finder regex
      bug_finder = re.compile(getattr(tree,
                                      'plugin_buglink_regex',
                                      r'(?i)bug\s+#?([0-9]+)'))
  
  
  class BugLinkHtmlifier(object):
      def __init__(self, text):
          self.text = text
  
      def refs(self):
          global name
          for m in bug_finder.finditer(self.text):
              bug = m.group(1)
              yield m.start(0), m.end(0), ([{
                  'text': "Lookup #%s" % bug,
                  'title': "Find this bug number at %s" % name,
                  'href': url % bug,
                  'icon': 'buglink'
              }], '')
  
      def regions(self):
          return []
  
      def annotations(self):
          return []
  
      def links(self):
          return []
  
  
  def htmlify(path, text):
      return BugLinkHtmlifier(text)
  
  
  __all__ = dxr.plugins.htmlifier_exports()
  
subject: Allow custom regexes for finding bug mentions. Close #158.