function rewriteLinksInMdContent(mdContent, filePath, { gitHubUrl, gitRootDir }) {
  /**
   * @param {string} href
   */
  const rewrite = href => {
    const relativeUrl = rootDirResolve(filePath, href, gitRootDir);
    if (relativeUrl) {
      const commitSha = process.env.GITHUB_SHA ? process.env.GITHUB_SHA : 'master';
      const githubWithCommitShaUrl = new URL(`blob/${commitSha}/`, gitHubUrl).href;
      const newUrl = new URL(relativeUrl, githubWithCommitShaUrl).href;
      return newUrl;
    }
    return href;
  };

  /**
   * @param {string} href
   * @param {string} title
   * @param {string} text
   */
  const mdLink = (href, title, text) =>
    `[${text}](${rewrite(href)}${title ? ` ${title.trim()}` : ''})`;

  /** @type {string[]} */
  const resultLinks = [];
  // /^!?\[(label)\]\(href(?:\s+(title))?\s*\)/
  const linkPattern = '!?\\[(.*)\\]\\(([^|\\s]*)( +(.*))?\\s*\\)'; // eslint-disable-line
  const matches = mdContent.match(new RegExp(linkPattern, 'g')) || [];

  matches.forEach(link => {
    let newLink = '';
    const parts = link.match(new RegExp(linkPattern));
    if (parts) {
      newLink = mdLink(parts[2], parts[3], parts[1]);
      if (parts[0][0] === '!') {
        // is an image
        newLink = `!${newLink}`;
      }
    }
    resultLinks.push(newLink);
  });

  // Now that we have our rewritten links, stitch back together the desired result
  const tokenPattern = /!?\[.*\]\([^|\s]*(?: +.*)?\s*\)/;
  const tokens = mdContent.split(new RegExp(tokenPattern, 'g'));

  /** @type {string[]} */
  const resultTokens = [];
  tokens.forEach((token, i) => {
    resultTokens.push(token + (resultLinks[i] || ''));
  });
  const resultContent = resultTokens.join('');
  return resultContent;
}
Rewrites all relative links of markdown content to absolute links.
Also includes images. See: https://github.com/tcort/markdown-link-extractor/blob/master/index.js
@param {string} mdContent - contents of .md file to parse
@param {string} filePath - local filesystem path of md file, like '/path/to/lion/packages/my-component/docs/myClass.md'
@param {object} options - configurantion object
@param {string} options.gitHubUrl - root github url for the absolute result links
@param {string} options.gitRootDir - root github directory to generate relative urls to it
@returns {string} adjusted contents of input md file (mdContent)