code: def extract_files(files):
      
      expanded_files = []
      legal_extensions = [".md", ".txt", ".rtf", ".html", ".tex", ".markdown"]
  
      for f in files:
          # If it's a directory, recursively walk through it and find the files.
          if os.path.isdir(f):
              for dir_, _, filenames in os.walk(f):
                  for filename in filenames:
                      fn, file_extension = os.path.splitext(filename)
                      if file_extension in legal_extensions:
                          joined_file = os.path.join(dir_, filename)
                          expanded_files.append(joined_file)
  
          # Otherwise add the file directly.
          else:
              expanded_files.append(f)
  
      return expanded_files
docs: Expand list of paths to include all text files matching the pattern.