All Projects → robinst → linkify

robinst / linkify

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Rust library to find links such as URLs and email addresses in plain text, handling surrounding punctuation correctly

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to linkify

linkify-plus-plus
A userscript/extension which can linkify almost everything. Based on Linkify Plus.
Stars: ✭ 78 (-46.58%)
Mutual labels:  url, linkify
Uri Components
League URI components objects
Stars: ✭ 244 (+67.12%)
Mutual labels:  url
New Github Issue Url
Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields
Stars: ✭ 170 (+16.44%)
Mutual labels:  url
Urlhub
URL shortener web application based on the Laravel PHP Framework.
Stars: ✭ 217 (+48.63%)
Mutual labels:  url
Nanoid
A tiny, secure, URL-friendly, unique string ID generator for Rust
Stars: ✭ 188 (+28.77%)
Mutual labels:  url
Pguri
uri type for PostgreSQL
Stars: ✭ 235 (+60.96%)
Mutual labels:  url
Modernsearchbar
The famous iOS search bar with auto completion feature implemented.
Stars: ✭ 167 (+14.38%)
Mutual labels:  url
parse-github-url
Parse a Github URL into an object. Supports a wide variety of GitHub URL formats.
Stars: ✭ 114 (-21.92%)
Mutual labels:  url
Scout
🔭 Lightweight URL fuzzer and spider: Discover a web server's undisclosed files, directories and VHOSTs
Stars: ✭ 241 (+65.07%)
Mutual labels:  url
Unbescape
Advanced yet easy to use escaping library for Java
Stars: ✭ 207 (+41.78%)
Mutual labels:  url
Verb
Organize and send HTTP requests from Emacs
Stars: ✭ 205 (+40.41%)
Mutual labels:  url
React Url Query
A library for managing state through query parameters in the URL in React
Stars: ✭ 195 (+33.56%)
Mutual labels:  url
Connector
Коннектор: удобный HTTP-клиент для 1С:Предприятие 8
Stars: ✭ 240 (+64.38%)
Mutual labels:  url
Urlbuilder
Java Builders: URL builder
Stars: ✭ 174 (+19.18%)
Mutual labels:  url
use-route-as-state
Use React Router route and query string as component state
Stars: ✭ 37 (-74.66%)
Mutual labels:  url
Furl
🌐 URL parsing and manipulation made easy.
Stars: ✭ 2,152 (+1373.97%)
Mutual labels:  url
Hyperlink
🔗 Immutable, Pythonic, correct URLs.
Stars: ✭ 198 (+35.62%)
Mutual labels:  url
Scala Uri
Simple scala library for building and parsing URIs
Stars: ✭ 225 (+54.11%)
Mutual labels:  url
Breviare
Small URL shortener made with the MERN Stack
Stars: ✭ 16 (-89.04%)
Mutual labels:  url
bifrost
🌉 The rainbow bridge. URL shortener for Vercel.
Stars: ✭ 28 (-80.82%)
Mutual labels:  url

Linkify

Linkify is a Rust library to find links such as URLs and email addresses in plain text. It's smart about where a link ends, such as with trailing punctuation.

Documentation Crate ci codecov

Introduction

Your reaction might be: "Do I need a library for this? Why not a regex?". Let's look at a few cases:

  • In http://example.com/. the link should not include the trailing dot
  • http://example.com/, should not include the trailing comma
  • (http://example.com/) should not include the parens

Seems simple enough. But then we also have these cases:

  • https://en.wikipedia.org/wiki/Link_(The_Legend_of_Zelda) should include the trailing paren
  • http://üñîçøðé.com/ä should also work for Unicode (including Emoji and Punycode)
  • <http://example.com/> should not include angle brackets

This library behaves as you'd expect in the above cases and many more. It uses a simple scan with linear runtime.

In addition to URLs, it can also find email addresses.

Demo 🧑‍🔬

Try it out online on the demo playground (Rust compiled to WebAssembly): https://robinst.github.io/linkify/

If you want to use it on the command line, try lychee. It uses linkify to extract all links and checks if they're valid, but it can also just print them like this:

$ echo 'Test https://example.org (and https://example.com)' | lychee --dump -
https://example.org/
https://example.com/

Usage

Basic usage:

extern crate linkify;

use linkify::{LinkFinder, LinkKind};

let input = "Have you seen http://example.com?";
let finder = LinkFinder::new();
let links: Vec<_> = finder.links(input).collect();

assert_eq!(1, links.len());
let link = &links[0];

assert_eq!("http://example.com", link.as_str());
assert_eq!(14, link.start());
assert_eq!(32, link.end());
assert_eq!(&LinkKind::Url, link.kind());

Option to allow URLs without schemes:

use linkify::LinkFinder;

let input = "Look, no scheme: example.org/foo";
let mut finder = LinkFinder::new();

// true by default
finder.url_must_have_scheme(false);

let links: Vec<_> = finder.links(input).collect();
assert_eq!(links[0].as_str(), "example.org/foo");

Restrict the kinds of links:

use linkify::{LinkFinder, LinkKind};

let input = "http://example.com and [email protected]";
let mut finder = LinkFinder::new();
finder.kinds(&[LinkKind::Email]);
let links: Vec<_> = finder.links(input).collect();

assert_eq!(1, links.len());
let link = &links[0];
assert_eq!("[email protected]", link.as_str());
assert_eq!(&LinkKind::Email, link.kind());

See full documentation on docs.rs.

Conformance

This crates makes an effort to respect the various standards, namely:

At the same time, it does not guarantee that the returned links are valid. If in doubt, it rather returns a link than skipping it.

If you need to validate URLs, e.g. for checking TLDs, use another library on the returned links.

Contributing

Pull requests, issues and comments welcome! Make sure to add tests for new features and bug fixes.

License

Linkify is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details. Opening a pull requests is assumed to signal agreement with these licensing terms.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].