@@ -37,7 +37,9 @@ Extract links:
37
37
import org.nibor.autolink.* ;
38
38
39
39
String input = " wow, so example: http://test.com" ;
40
- LinkExtractor linkExtractor = LinkExtractor . builder(). build();
40
+ LinkExtractor linkExtractor = LinkExtractor . builder()
41
+ .linkTypes(EnumSet . of(LinkType . URL , LinkType . WWW , LinkType . EMAIL ))
42
+ .build();
41
43
Iterable<LinkSpan > links = linkExtractor. extractLinks(input);
42
44
LinkSpan link = links. iterator(). next();
43
45
link. getType(); // LinkType.URL
@@ -46,7 +48,13 @@ link.getEndIndex(); // 32
46
48
input. substring(link. getBeginIndex(), link. getEndIndex()); // "http://test.com"
47
49
```
48
50
49
- Wrapping URLs in an <a > tag (doesn't handle escaping, uses Java 8):
51
+ Note that by default all supported types of links are extracted. If
52
+ you're only interested in specific types, narrow it down using the
53
+ ` linkTypes ` method.
54
+
55
+ There's also a static method to replace links found in the text. Here's
56
+ an example of using that for wrapping URLs in an ` <a> ` tag. Note that it
57
+ doesn't handle escaping at all:
50
58
51
59
``` java
52
60
import org.nibor.autolink.* ;
@@ -91,7 +99,8 @@ Example input and linked result:
91
99
[ https://en.wikipedia.org/wiki/Link_(The_Legend_of_Zelda) ] ( )
92
100
* ` http://üñîçøðé.com/ ` → [ http://üñîçøðé.com/ ] ( )
93
101
94
- Also see [ test cases] ( src/test/java/org/nibor/autolink/AutolinkUrlTest.java ) .
102
+ Use ` LinkType.URL ` for this, and see [ test
103
+ cases here] ( src/test/java/org/nibor/autolink/AutolinkUrlTest.java ) .
95
104
96
105
### WWW link extraction
97
106
@@ -112,7 +121,8 @@ Not supported:
112
121
113
122
The domain must have at least 3 parts, so ` www.com ` is not valid, but ` www.something.co.uk ` is.
114
123
115
- Also see [ test cases] ( src/test/java/org/nibor/autolink/AutolinkWwwTest.java ) .
124
+ Use ` LinkType.WWW ` for this, and see [ test
125
+ cases here] ( src/test/java/org/nibor/autolink/AutolinkWwwTest.java ) .
116
126
117
127
### Email address extraction
118
128
@@ -134,7 +144,8 @@ Not supported:
134
144
Note that the domain must have at least one dot (e.g. ` foo@com ` isn't
135
145
matched), unless the ` emailDomainMustHaveDot ` option is disabled.
136
146
137
- Also see [ test cases] ( src/test/java/org/nibor/autolink/AutolinkEmailTest.java ) .
147
+ Use ` LinkType.EMAIL ` for this, and see [ test cases
148
+ here] ( src/test/java/org/nibor/autolink/AutolinkEmailTest.java ) .
138
149
139
150
Contributing
140
151
------------
0 commit comments