Skip to content

Commit 6dd0de6

Browse files
committed
Extend README and make LinkType more explicit
1 parent 6444b6c commit 6dd0de6

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ Extract links:
3737
import org.nibor.autolink.*;
3838

3939
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();
4143
Iterable<LinkSpan> links = linkExtractor.extractLinks(input);
4244
LinkSpan link = links.iterator().next();
4345
link.getType(); // LinkType.URL
@@ -46,7 +48,13 @@ link.getEndIndex(); // 32
4648
input.substring(link.getBeginIndex(), link.getEndIndex()); // "http://test.com"
4749
```
4850

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:
5058

5159
```java
5260
import org.nibor.autolink.*;
@@ -91,7 +99,8 @@ Example input and linked result:
9199
[https://en.wikipedia.org/wiki/Link_(The_Legend_of_Zelda)]()
92100
* `http://üñîçøðé.com/`[http://üñîçøðé.com/]()
93101

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).
95104

96105
### WWW link extraction
97106

@@ -112,7 +121,8 @@ Not supported:
112121

113122
The domain must have at least 3 parts, so `www.com` is not valid, but `www.something.co.uk` is.
114123

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).
116126

117127
### Email address extraction
118128

@@ -134,7 +144,8 @@ Not supported:
134144
Note that the domain must have at least one dot (e.g. `foo@com` isn't
135145
matched), unless the `emailDomainMustHaveDot` option is disabled.
136146

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).
138149

139150
Contributing
140151
------------

0 commit comments

Comments
 (0)