Replace any links and emails found in your text with HTML anchor elements and return properly escaped and safe HTML.
var linkify = require("html-linkify");
var text = linkify(
"Visit http://foo.com!\n" +
"Email [email protected]\n" +
"<script>alert('xss!')</script>");
console.log(text);
// -> Visit <a href="http://foo.com">http://foo.com</a>!
// Email <a href="mailto:[email protected]">[email protected]</a>
// <script>alert('xss!')</script>
Replace any links found in the input text with anchor elements.
Options:
options.attributes
: A mapping of attributes to be added to the generated anchor elements (in addition to href).options.escape
: Whether surrounding HTML tags should be escaped or not (default:true
).
- Allow arbitrary user-definable replacing
npm install html-linkify