index.js 759 字节
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
'use strict';

/**
 * Create a markdown-formatted link from the given values.
 *
 * ```js
 * mdlink('micromatch', 'https://github.com/jonschlinkert/micromatch', 'hover title');
 * //=> [micromatch](https://github.com/jonschlinkert/micromatch "hover title")
 * ```
 *
 * @name link
 * @param  {String} `anchor`
 * @param  {String} `href`
 * @param  {String} `title`
 * @api public
 */

module.exports = function link(anchor, href, title) {
  if (typeof anchor !== 'string') {
    throw new TypeError('markdown-link expects anchor to be a string.');
  }
  if (typeof href !== 'string') {
    throw new TypeError('markdown-link expects href to be a string.');
  }

  title = title ? ' "' + title + '"' : '';
  return '[' + anchor + '](' + href + title + ')';
};