input: Write a function to flatten out a folder based docbook manual into a flat structure and update links accordingly.
  assert flatten('path/to/root', 'path/to/output') == None # assuming the function modifies files in place and returns None
output: import os
  import shutil
  from bs4 import BeautifulSoup
  
  def flatten(input_folder, output_folder):
      if not os.path.exists(output_folder):
          os.makedirs(output_folder)
  
      file_map = {}
      
      for root, _, files in os.walk(input_folder):
          for file in files:
              old_path = os.path.join(root, file)
              new_path = os.path.join(output_folder, os.path.relpath(old_path, input_folder).replace(os.sep, '_'))
              shutil.copyfile(old_path, new_path)
              file_map[old_path] = new_path
  
      for file in file_map.values():
          with open(file, 'r', encoding='utf-8') as f:
              soup = BeautifulSoup(f, 'xml')
          
          for link in soup.find_all(['xref', 'link', 'ulink']):
              if link.has_attr('href'):
                  href = link['href']
                  if not href.startswith('http'):
                      abs_path = os.path.abspath(os.path.join(input_folder, href))
                      if abs_path in file_map:
                          link['href'] = os.path.basename(file_map[abs_path])
  
          with open(file, 'w', encoding='utf-8') as f:
              f.write(str(soup))