to-mention-link
Version:
Create links from @ mentions.
98 lines (62 loc) • 3.74 kB
Markdown
# to-mention-link [](https://www.npmjs.com/package/to-mention-link) [](https://npmjs.org/package/to-mention-link) [](https://travis-ci.org/doowb/to-mention-link)
Create links from @ mentions.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save to-mention-link
```
## Usage
```js
var toMention = require('to-mention-link');
```
## API
### [toMention](index.js#L36)
Turn @ mentions in a string into links. Defaults to markdown links but allows html and custom link renders. See the [example](./example.js) for more details.
**Params**
* `str` **{String}**: Input string containing @ mentions.
* `options` **{Options}**: Additional options to control url and link rendering.
* `options.url` **{String}**: Specify the url to be used. Defaults to "https://github.com"
* `options.title` **{String|Function}**: Specify the title to be used. May be a function that takes the parsed @ mention and returns a title string.
* `options.renderer` **{String|Function}**: Specify the link renderer to use. Must be a rendered on the [renderers](#renderers) object. May be a function that takes the mention, url, and title to be rendered. Defaults to "md".
* `returns` **{String}**: Transformed string with @ mentions as links.
**Example**
```js
// defaults to github urls
console.log(toMention('- @doowb\n- @jonschlinkert'));
//=> - [doowb](https://github.com/doowb)
//=> - [jonschlinkert](https://github.com/jonschlinkert)
// use custom url
console.log(toMention('- @doowb\n- @jonschlinkert', {url: 'https://twitter.com'}));
//=> - [doowb](https://twitter.com/doowb)
//=> - [jonschlinkert](https://twitter.com/jonschlinkert)
```
## Renderers
Renderers are functions that take the mention, a url, and an optional title and return a formatted link string.
Included renders are "md" and "html". "md" is provided by [markdown-link](https://github.com/jonschlinkert/markdown-link). Additional renderers may be added and used
by passing their name on the `options.renderer` option.
## About
### Related projects
[parse-mentions](https://www.npmjs.com/package/parse-mentions): Parse and optionally replace @ mentions from a string of text. | [homepage](https://github.com/doowb/parse-mentions "Parse and optionally replace @ mentions from a string of text.")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Please read the [contributing guide](contributing.md) for avice on opening issues, pull requests, and coding standards.
### Building docs
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install -g verb verb-generate-readme && verb
```
### Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
### Author
**Brian Woodward**
* [github/doowb](https://github.com/doowb)
* [twitter/doowb](http://twitter.com/doowb)
### License
Copyright © 2016, [Brian Woodward](https://github.com/doowb).
Released under the [MIT license](https://github.com/doowb/to-mention-link/blob/master/LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on September 24, 2016._