|
| 1 | +## autolink-js |
| 2 | + |
| 3 | +autolink-js is a small, simple, and tested JavaScript tool that takes |
| 4 | +your blobs of text, finds URLs within it, and hyperlinks them. |
| 5 | + |
| 6 | +### Why bother releasing such a tiny little method? |
| 7 | + |
| 8 | +I recently needed to find and hyperlink URLs in user-submitted text |
| 9 | +and was surprised to find that doing what seemed like such a simple task wasn't already a |
| 10 | +Solved Problem. Different regex solutions led to different unwanted side |
| 11 | +effects, and other utilities were far, far more complex and feature rich |
| 12 | +than I needed. |
| 13 | + |
| 14 | +### Basic Usage |
| 15 | + |
| 16 | +autolink-js adds an autoLink() method to JavaScript's String prototype, |
| 17 | +so you can use it on any JavaScript string. Take a look at the tests, |
| 18 | +but essentially, it works like this: |
| 19 | + |
| 20 | + // Input |
| 21 | + "This is a link to Google http://google.com".autoLink() |
| 22 | + |
| 23 | + // Output |
| 24 | + "This is a link to Google <a href='http://google.com'>http://google.com</a>" |
| 25 | + |
| 26 | +### Additional Options |
| 27 | + |
| 28 | +You can pass any additional HTML attributes to the anchor tag with a JavaScript object, like this: |
| 29 | + |
| 30 | + // Input |
| 31 | + "This is a link to Google http://google.com".autoLink({ target: "_blank", rel: "nofollow", id: "1" }) |
| 32 | + |
| 33 | + // Output |
| 34 | + "This is a link to Google <a href='http://google.com' target='_blank' rel='nofollow' id='1'>http://google.com</a>" |
| 35 | + |
| 36 | +### Example |
| 37 | + |
| 38 | +Open example/example.html in your web browser for a simple but |
| 39 | +full-featured example. |
| 40 | + |
| 41 | +### Running the tests |
| 42 | + |
| 43 | +After cloning, this repository, simply open test/suite.html in your web |
| 44 | +browser. The tests will run automatically. |
0 commit comments