old_contents: """Example processor for the IMPORTCATEGORY tag. This will be replaced with
  something more sophisticated and should be in an ATF-specific submodule"""
  from regparser.tree.struct import Node
  from regparser.tree.xml_parser import flatsubtree_processor
  
  
  class ImportCategoryMatcher(flatsubtree_processor.FlatsubtreeMatcher):
      def __init__(self):
          super(ImportCategoryMatcher, self).__init__(tags=['IMPORTCATEGORY'],
                                                      node_type=Node.EXTRACT)
  
new_contents: from copy import deepcopy
  import logging
  import re
  
  from regparser.tree.depth import markers as mtypes
  from regparser.tree.paragraph import hash_for_paragraph
  from regparser.tree.struct import Node
  from regparser.tree.xml_parser import paragraph_processor, tree_utils
  
  
  class ImportCategoryMatcher(paragraph_processor.BaseMatcher):
      """The IMPORTCATEGORY gets converted into a subtree with an appropriate
      title and unique paragraph marker"""
      CATEGORY_RE = re.compile(r'categor(y|ies) (?P<category>[ivx]+).*',
                               re.IGNORECASE)
  
      def matches(self, xml):
          return xml.tag == 'IMPORTCATEGORY'
  
      def derive_nodes(self, xml, processor):
          """Finds and deletes the category header before recursing. Adds this
          header as a title."""
          xml = deepcopy(xml)     # we'll be modifying this
          header = xml.xpath('./HD')[0]
          xml.remove(header)
          header_text = tree_utils.get_node_text(header)
  
          node = Node(title=header_text, label=[self.marker(header_text)])
          return [processor.process(xml, node)]
  
      @classmethod
      def marker(cls, header_text):
          """Derive a unique, repeatable identifier for this subtree. This
          allows the same category to be reordered (e.g. if a note has been
          added), or a header with multiple reserved categories to be split
          (which would also re-order the categories that followed)"""
          match = cls.CATEGORY_RE.match(header_text)
          if match:
              return 'p{}'.format(hash_for_paragraph(match.group('category')))
          else:
              logging.warn("Couldn't derive category: %s", header_text)
              return mtypes.MARKERLESS
  
subject: Improve IMPORTCATEGORY handler