text-url-to-html-link
It's a simple function that fetches all the urls in a string, and transforms them into HTML links (tag )
Install
yarn add text-url-to-html-link
This package is build with Parcel Builder.
Get started
const textUrlToHtmlLink = ;// or const myText = `Create Share Links to send your expressions to co-workers or link to them on Twitter or your blog [ex. http://RegExr.com?2rjl6]. Built by gskinner.com with Flex 3 [adobe.com/go/flex] and Spelling Plus Library for text highlighting [gskinner.com/products/spl].`; console;
Result with restrictive regex:
Create Share Links to send your expressions to co-workers or link to them on Twitter or your blog [ex. <a href="http://RegExr.com?2rjl6" >http://RegExr.com?2rjl6</a>]. Built by gskinner.com with Flex 3 [adobe.com/go/flex] and Spelling Plus Library for text highlighting [gskinner.com/products/spl].
Result with less restrictive regex:
Create Share Links to send your expressions to co-workers or link to them on Twitter or your blog [ex. <a href="http://RegExr.com?2rjl6" >http://RegExr.com?2rjl6</a>]. Built by <a href="gskinner.com" >gskinner.com</a> with Flex 3 [<a href="adobe.com/go/flex" >adobe.com/go/flex</a>] and Spelling Plus Library for text highlighting [<a href="gskinner.com/products/spl" >gskinner.com/products/spl</a>].
Options
Here is signature:
textUrlToHtmlLink(text, htmlAttrs, restrictive)
htmlAttrs
: an object of a-tag Html attributesrestrictive
: boolean to set restrictive mode