def reverse_relative_links(md_files, root=None):
    """

    Takes a list of MarkdownDocument and constructs a relative link
    lookup dictionary. It constructs a dictionary that is keyed to the
    filename and is mapped to the list of relative URLs contained
    within the document.

    # Parameters

    md_files:list(MarkdownDocument)
        - The list of MarkdownDocument objects to create a reverse
          lookup list from.
        - The list well be keyed by the markdown file path and contain a
          list of internal links resolved to the proper path

    root:pathlib.Path
        - The root folder to make links relative to.

    # Return

    a dictionary

    """

    md_link_lookup = {}

    for md in md_files:
        key = md.filename

        if root:
            key = key.relative_to(root)

        for url in md.relative_links():
            p = md.filename.parent.joinpath(url[1]["md"]).resolve()

            if root:
                p = p.relative_to(root)

            md_link_lookup.setdefault(key, []).append(p)

    return md_link_lookup