Skip to content

Commit 8d77019

Browse files
committed
Add introduction
1 parent 65bbcc5 commit 8d77019

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

README.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,38 @@ autolink-java
22
=============
33

44
Java library to extract links such as URLs and email addresses from plain text.
5-
Fast, small and smart about recognizing where links end.
5+
It's smart about where a link ends, such as with trailing punctuation.
66

7-
Inspired by [Rinku](https://github.com/vmg/rinku). Similar to it, regular
8-
expressions are not used. Instead, the input text is parsed in one pass with
9-
limited backtracking.
7+
[![ci](https://github.com/robinst/autolink-java/workflows/ci/badge.svg)](https://github.com/robinst/autolink-java/actions?query=workflow%3Aci)
8+
[![Coverage status](https://codecov.io/gh/robinst/autolink-java/branch/main/graph/badge.svg)](https://codecov.io/gh/robinst/autolink-java)
9+
[![Maven Central status](https://img.shields.io/maven-central/v/org.nibor.autolink/autolink.svg)](https://search.maven.org/search?q=g:org.nibor.autolink%20AND%20a:autolink&core=gav)
10+
11+
Introduction
12+
------------
13+
14+
You might think: "Do I need a library for this? I can just write a regex for this!".
15+
Let's look at a few cases:
16+
17+
* In text like `https://example.com/.` the link should not include the trailing dot
18+
* `https://example.com/,` should not include the trailing comma
19+
* `(https://example.com/)` should not include the parens
20+
21+
Seems simple enough. But then we also have these cases:
22+
23+
* `https://en.wikipedia.org/wiki/Link_(The_Legend_of_Zelda)` should include the trailing paren
24+
* `https://üñîçøðé.com/ä` should also work for Unicode (including Emoji and Punycode)
25+
* `<https://example.com/>` should not include angle brackets
26+
27+
This library behaves as you'd expect in the above cases and many more.
28+
It parses the input text in one pass with limited backtracking.
29+
30+
Thanks to [Rinku](https://github.com/vmg/rinku) for the inspiration.
1031

11-
This library requires at least Java 7 (tested up to Java 11). It works on Android (minimum API level 15). It has no external dependencies.
32+
Usage
33+
-----
1234

13-
[Demo](https://onecompiler.com/java/3vjubz6sz)
35+
This library requires at least Java 7 (tested up to Java 11). It works on Android (minimum API level 15).
36+
It has no external dependencies.
1437

1538
Maven coordinates
1639
(see
@@ -25,15 +48,7 @@ for other build systems):
2548
</dependency>
2649
```
2750

28-
[![ci](https://github.com/robinst/autolink-java/workflows/ci/badge.svg)](https://github.com/robinst/autolink-java/actions?query=workflow%3Aci)
29-
[![Coverage status](https://codecov.io/gh/robinst/autolink-java/branch/main/graph/badge.svg)](https://codecov.io/gh/robinst/autolink-java)
30-
[![Maven Central status](https://img.shields.io/maven-central/v/org.nibor.autolink/autolink.svg)](https://search.maven.org/search?q=g:org.nibor.autolink%20AND%20a:autolink&core=gav)
31-
32-
33-
Usage
34-
-----
35-
36-
Extract links:
51+
Extracting links:
3752

3853
```java
3954
import org.nibor.autolink.*;
@@ -54,10 +69,12 @@ Note that by default all supported types of links are extracted. If
5469
you're only interested in specific types, narrow it down using the
5570
`linkTypes` method.
5671

57-
There's another method which is convenient for when you want to transform
58-
all of the input text to something else. Here's an example of using that
59-
to transform the text to HTML and wrapping URLs in an `<a>` tag (escaping
60-
is done using owasp-java-encoder):
72+
The above returns all the links. Sometimes what you want to do is go over some input,
73+
process the links and keep the surrounding text. For that case,
74+
there's an `extractSpans` method.
75+
76+
Here's an example of using that to transform the text to HTML and wrapping URLs in
77+
an `<a>` tag (escaping is done using owasp-java-encoder):
6178

6279
```java
6380
import org.nibor.autolink.*;

0 commit comments

Comments
 (0)