to-mention-link
v0.1.0
Published
Create links from @ mentions.
Downloads
113
Readme
to-mention-link
Create links from @ mentions.
Install
Install with npm:
$ npm install --save to-mention-link
Usage
var toMention = require('to-mention-link');
API
toMention
Turn @ mentions in a string into links. Defaults to markdown links but allows html and custom link renders. See the example 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 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
// 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. Additional renderers may be added and used
by passing their name on the options.renderer
option.
About
Related projects
parse-mentions: Parse and optionally replace @ mentions from a string of text. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for avice on opening issues, pull requests, and coding standards.
Building docs
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Brian Woodward
License
Copyright © 2016, Brian Woodward. Released under the MIT license.
This file was generated by verb-generate-readme, v0.1.30, on September 24, 2016.