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

Feature Request: A way to add custom attributes in the anchor links #152

Closed shyamal890 closed 8 years ago

shyamal890 commented 8 years ago

For example I would like to add 'contenteditable="false" ' in every link generated

gregjacobs commented 8 years ago

Hey, you can use the replaceFn option to do this. Something like the following:

Autolinker.link( myText, {
    replaceFn : function( autolinker, match ) {
        var tag = match.buildTag();  // returns an `Autolinker.HtmlTag` instance
        tag.setAttr( 'contenteditable', 'false' );

        return tag;
    }
} );

Make sure you have v0.25.0 which has the latest API