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

Change the text of urls #50

Closed gozhang7 closed 10 years ago

gozhang7 commented 10 years ago

Hi, you project is really helpful! Thanks for your hard work! I am wondering is it possible for me to specify the text that the urls will be showed, like a text option? Eventually I would like some effect like Url , is it possible for me to do that? Thanks!

jjwill commented 10 years ago

+1 I really like the behavior that Jira/Crucible have where www.this.link and [this other link|other.link] are formatted as links. The flavor of link formatting rules differ from site to site though. I know github uses markdown.

gregjacobs commented 10 years ago

@jjwill Sorry, Autolinker isn't really meant to be a markdown parser. Could run the markdown parser before running Autolinker though, and things should still work well.

@tibeT7 I finally added a feature to allow text replacements of links, using a replaceFn, and exposing some of the Autolinker internals. Try this out:

Autolinker.link( text, {
    replaceFn : function( autolinker, match ) {
        var tag = autolinker.getTagBuilder().build( match );  // returns an `Autolinker.HtmlTag` instance
        tag.setInnerHtml( 'New Tag Text' );

        return tag;
    }
} );