docs: def add_module_file(plpy, td):
      """Database trigger for adding a module file.
  
      When a legacy ``index.cnxml`` is added, this trigger
      transforms it into html and stores it as ``index.cnxml.html``.
      When a cnx-publishing ``index.cnxml.html`` is added, this trigger
      checks if ``index.html.cnxml`` exists before
      transforming it into cnxml and stores it as ``index.html.cnxml``.
  
      Note, we do not use ``index.html`` over ``index.cnxml.html``, because
      legacy allows users to name files ``index.html``.
  
      """
      module_ident = td['new']['module_ident']
      filename = td['new']['filename']
      msg = "produce {}->{} for module_ident = {}"
  
      def check_for(filenames, module_ident):
          """Find filenames associated with module_ident.
  
          Check for a file at ``filename`` associated with
          module at ``module_ident``.
          """
          stmt = plpy.prepare("""\
  SELECT TRUE AS exists FROM module_files
  WHERE filename = $1 AND module_ident = $2""", ['text', 'integer'])
          any_exist = False
          for filename in filenames:
              result = plpy.execute(stmt, [filename, module_ident])
              try:
                  exists = result[0]['exists']
              except IndexError:
                  exists = False
              any_exist = any_exist or exists
          return any_exist
  
      # Declare the content producer function variable,
      #   because it is possible that it will not be assigned.
      producer_func = None
      if filename == 'index.cnxml':
          new_filenames = ('index.cnxml.html',)
          # Transform content to html.
          other_exists = check_for(new_filenames, module_ident)
          if not other_exists:
              msg = msg.format('cnxml', 'html', module_ident)
              producer_func = produce_html_for_module
      elif filename == 'index.cnxml.html':
          new_filenames = ('index.html.cnxml', 'index.cnxml',)
          # Transform content to cnxml.
          other_exists = check_for(new_filenames, module_ident)
          if not other_exists:
              msg = msg.format('html', 'cnxml', module_ident)
              producer_func = produce_cnxml_for_module
      else:
          # Not one of the special named files.
          return  # skip
  
      plpy.info(msg)
      if producer_func is not None:
          producer_func(plpy,
                        module_ident,
                        source_filename=filename,
                        destination_filenames=new_filenames)
      _transform_abstract(plpy, module_ident)
      return