toMarkdownLinkFormat = function(link, doc, code) {
  var type, desc;

  // Split type and description
  var i = link.indexOf(' ');
  if (i == -1) {
    desc = type = link;
  } else {
    desc = link.substr(i).trim();
    type = link.substr(0, i).trim();
  }
  if (code) {
    desc = '{@code ' + desc + '}'
  }
  desc = desc.replace(new RegExp('\n', 'g'), ' ');

  if (desc in externalTypes) {
    type = externalTypes[desc];
  }

  if (!type.match(/^https?:\/\//)) {
    // Remove extra '()' at the end of types
    if (type.substr(-2) == '()') {
      type = type.substr(0, type.length - 2);
    }

    // Expand '#' at the start of types
    if (type[0] == '#') {
      type = doc.name.substr(0, doc.name.lastIndexOf('.') + 1) + type.substr(1);
    }

    // Replace '#' in the middle of types with '.'
    type = type.replace(new RegExp('#', 'g'), '.prototype.');

    // Only create a link if it's in the API
    if (!typeTable[type]) {
      return desc;
    }
  }
  return '[' + desc + '](' + type + ')';
}
Takes a link of the format 'type' or 'type description' and creates one of
the format '[description](type)'.

Also does some minor reformatting of the type.

@param {string} link The raw link.
@param {!Object} doc Current document.
@return {string} A link for the type.