code: def fixup_internal_links(config, soups):
    
    # Pages can come from different dirs; they can go to different dirs.
    # Thus, there's some relative-path-computing here.
    reverse_directory = {}
    for d, s in config['sources'].items():
      reverse_directory[s] = d
    for name, soup in soups.items():
      old_src_dir = os.path.dirname(config['sources'][name])
      for tag in soup.find_all(True):
        if not 'href' in tag.attrs:
          continue
        old_rel_path = tag['href'].split('#')[0]
        old_dst = os.path.normpath(os.path.join(old_src_dir, old_rel_path))
        if not old_dst in reverse_directory:
          continue
        new_dst = reverse_directory[old_dst] + '.html'
        new_rel_path = rel_href(name, new_dst)
        # string replace instead of assign to not loose anchor in foo.html#anchor
        tag['href'] = tag['href'].replace(old_rel_path, new_rel_path, 1)
docs: Find href="..." links that link to pages in our docset; fix them up.
  
    We don't preserve relative paths between files as we copy-transform them
    from source to dest. So adjust the paths to work with new locations.