1Linkify
2=======
3
4Linkify is a Rust library to find links such as URLs and email addresses in
5plain text. It's smart about where a link ends, such as with trailing
6punctuation.
7
8[![Documentation](https://docs.rs/linkify/badge.svg)](https://docs.rs/linkify)
9[![Crate](https://img.shields.io/crates/v/linkify.svg)](https://crates.io/crates/linkify)
10[![Build Status](https://travis-ci.org/robinst/linkify.svg?branch=master)](https://travis-ci.org/robinst/linkify)
11[![codecov](https://codecov.io/gh/robinst/linkify/branch/master/graph/badge.svg)](https://codecov.io/gh/robinst/linkify)
12
13## Introduction
14
15Your reaction might be: "Do I need a library for this? Why not a regex?".
16Let's look at a few cases:
17
18* In `http://example.com/.` the link should not include the trailing dot
19* `http://example.com/,` should not include the trailing comma
20* `(http://example.com/)` should not include the parens
21
22Seems simple enough. But then we also have these cases:
23
24* `https://en.wikipedia.org/wiki/Link_(The_Legend_of_Zelda)` should include the trailing paren
25* `http://üñîçøðé.com/ä` should also work for Unicode (including Emoji and Punycode)
26* `<http://example.com/>` should not include angle brackets
27
28This library behaves as you'd expect in the above cases and many more.
29It uses a simple scan with linear runtime.
30
31In addition to URLs, it can also find emails.
32
33## Usage
34
35Basic usage:
36
37```rust
38extern crate linkify;
39
40use linkify::{LinkFinder, LinkKind};
41
42let input = "Have you seen http://example.com?";
43let finder = LinkFinder::new();
44let links: Vec<_> = finder.links(input).collect();
45
46assert_eq!(1, links.len());
47let link = &links[0];
48
49assert_eq!("http://example.com", link.as_str());
50assert_eq!(14, link.start());
51assert_eq!(32, link.end());
52assert_eq!(&LinkKind::Url, link.kind());
53```
54
55Restrict the kinds of links:
56
57```rust
58use linkify::{LinkFinder, LinkKind};
59
60let input = "http://example.com and foo@example.com";
61let mut finder = LinkFinder::new();
62finder.kinds(&[LinkKind::Email]);
63let links: Vec<_> = finder.links(input).collect();
64
65assert_eq!(1, links.len());
66let link = &links[0];
67assert_eq!("foo@example.com", link.as_str());
68assert_eq!(&LinkKind::Email, link.kind());
69```
70
71See full documentation on [docs.rs](https://docs.rs/linkify).
72
73## Conformance
74
75This crates makes an effort to respect the various standards, namely:
76
77* [RFC 3986] and [RFC 3987] for URLs
78* [RFC 5321] and [RFC 6531] for emails (except IP addresses and quoting)
79
80At the same time, it does not guarantee that the returned links are valid.
81If in doubt, it rather returns a link than skipping it.
82
83If you need to validate URLs, e.g. for checking TLDs, use another library on
84the returned links.
85
86## Contributing
87
88Pull requests, issues and comments welcome! Make sure to add tests for
89new features and bug fixes.
90
91## License
92
93Linkify is distributed under the terms of both the MIT license and the
94Apache License (Version 2.0). See [LICENSE-APACHE](LICENSE-APACHE) and
95[LICENSE-MIT](LICENSE-MIT) for details. Opening a pull requests is
96assumed to signal agreement with these licensing terms.
97
98[RFC 3986]: https://tools.ietf.org/search/rfc3986
99[RFC 3987]: https://tools.ietf.org/search/rfc3987
100[RFC 5321]: https://tools.ietf.org/search/rfc5321
101[RFC 6531]: https://tools.ietf.org/search/rfc6531
102