gregjacobs / Autolinker.js

Utility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML
MIT License
1.48k stars 238 forks source link

Unlink enhancement request #49

Closed pauliew closed 10 years ago

pauliew commented 10 years ago

It would be really helpful if you could add an option to replace the urls with pure text. For example say in a system where a user has an option to allow links or redact them. And it would be great if you could pass in text that will be displayed with the redacted url.

E.g.

if( linksAllowed ){

var linkedText = autolinker.link( textToLinkOrRedact ); } else{ var linkedText = autolinker.redact( textToLinkOrRedact, '[The link was removed]'); }

gregjacobs commented 10 years ago

Decades late.. but try this with v0.12.0:

var linkedText = Autolinker.link( text, {
    replaceFn : function( autolinker, match ) {
        return "[The link was removed]";
    }
} );