You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](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.
10
31
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
+
-----
12
34
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).
[](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:
37
52
38
53
```java
39
54
importorg.nibor.autolink.*;
@@ -54,10 +69,12 @@ Note that by default all supported types of links are extracted. If
54
69
you're only interested in specific types, narrow it down using the
55
70
`linkTypes` method.
56
71
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):
0 commit comments