Skip to content

Commit e49094c

Browse files
committed
Address PR Comments 2
1 parent 64f76d9 commit e49094c

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ with the exception that 0.x versions can break between minor versions.
1010
### Added
1111
- Autolink extension: Now supports configuration of different link types that
1212
should be recognized and converted to links. See `AutolinkExtension#builder`
13-
| Type | Default? | Description |
14-
|---------|----------|-----------------------------------------------------------|
15-
| `URL` | Yes | URL with a protocol such as `https://example.com` |
16-
| `EMAIL` | Yes | Email address such as `[email protected]` |
17-
| `WWW` | No | An address beginning with `www` such as `www.example.com` |
13+
14+
| Type | Default? | Description |
15+
|---------|----------|--------------------------------------------------------|
16+
| `URL` | Yes | URL with a protocol such as `https://example.com` |
17+
| `EMAIL` | Yes | Email address such as `[email protected]` |
18+
| `WWW` | Yes | Address beginning with `www` such as `www.example.com` |
19+
20+
> [!NOTE]
21+
>
22+
> This changes the behavior of `AutolinkExtension.create()` to now also include
23+
> `WWW` links by default. To re-enable the previous behavior, use:
24+
>
25+
> ```java
26+
> AutolinkExtension.builder().linkTypes(AutolinkType.URL, AutolinkType.EMAIL).build();
27+
> ```
1828
1929
## [0.26.0] - 2025-09-13
2030
### Changed

commonmark-ext-autolink/src/main/java/org/commonmark/ext/autolink/AutolinkExtension.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public void extend(Parser.Builder parserBuilder) {
4848

4949
public static class Builder {
5050

51-
private Set<AutolinkType> linkTypes = EnumSet.of(AutolinkType.URL, AutolinkType.EMAIL);
51+
private Set<AutolinkType> linkTypes = EnumSet.allOf(AutolinkType.class);
5252

5353
/**
54-
* @param linkTypes the link types that should be converted. By default, {@link AutolinkType#URL}
55-
* and {@link AutolinkType#EMAIL} are converted.
54+
* @param linkTypes the link types that should be converted. By default,
55+
* all {@link AutolinkType}s are converted.
5656
* @return {@code this}
5757
*/
5858
public Builder linkTypes(AutolinkType... linkTypes) {
@@ -64,8 +64,8 @@ public Builder linkTypes(AutolinkType... linkTypes) {
6464
}
6565

6666
/**
67-
* @param linkTypes the link types that should be converted. By default, {@link AutolinkType#URL}
68-
* and {@link AutolinkType#EMAIL} are converted.
67+
* @param linkTypes the link types that should be converted. By default,
68+
* all {@link AutolinkType}s are converted.
6969
* @return {@code this}
7070
*/
7171
public Builder linkTypes(Set<AutolinkType> linkTypes) {

commonmark-ext-autolink/src/main/java/org/commonmark/ext/autolink/internal/AutolinkPostProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ private static String getDestination(LinkSpan linkSpan, String linkText) {
100100
if (type == LinkType.EMAIL) {
101101
return "mailto:" + linkText;
102102
} else if (type == LinkType.WWW) {
103-
return "https://" + linkText;
103+
// Use http instead of https (see https://github.github.com/gfm/#extended-www-autolink)
104+
return "http://" + linkText;
104105
} else {
105106
return linkText;
106107
}

commonmark-ext-autolink/src/test/java/org/commonmark/ext/autolink/AutolinkTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public class AutolinkTest extends RenderingTestCase {
1919
private static final Parser PARSER = Parser.builder().extensions(EXTENSIONS).build();
2020
private static final HtmlRenderer RENDERER = HtmlRenderer.builder().extensions(EXTENSIONS).build();
2121

22-
private static final Set<Extension> WWW_EXTENSIONS = Set.of(AutolinkExtension.builder()
23-
.linkTypes(AutolinkType.URL, AutolinkType.EMAIL, AutolinkType.WWW)
22+
private static final Set<Extension> NO_WWW_EXTENSIONS = Set.of(AutolinkExtension.builder()
23+
.linkTypes(AutolinkType.URL, AutolinkType.EMAIL)
2424
.build());
25-
private static final Parser WWW_PARSER = Parser.builder().extensions(WWW_EXTENSIONS).build();
26-
private static final HtmlRenderer WWW_RENDERER = HtmlRenderer.builder().extensions(WWW_EXTENSIONS).build();
25+
private static final Parser NO_WWW_PARSER = Parser.builder().extensions(NO_WWW_EXTENSIONS).build();
26+
private static final HtmlRenderer NO_WWW_RENDERER = HtmlRenderer.builder().extensions(NO_WWW_EXTENSIONS).build();
2727

2828
@Test
2929
public void oneTextNode() {
@@ -64,15 +64,15 @@ public void dontLinkTextWithinLinks() {
6464
}
6565

6666
@Test
67-
public void wwwLinksDontWorkByDefault() {
67+
public void wwwLinks() {
6868
assertRendering("www.example.com",
69-
"<p>www.example.com</p>\n");
69+
"<p><a href=\"https://www.example.com\">www.example.com</a></p>\n");
7070
}
7171

7272
@Test
73-
public void wwwLinks() {
74-
String html = WWW_RENDERER.render(WWW_PARSER.parse("www.example.com"));
75-
assertThat(html).isEqualTo("<p><a href=\"https://www.example.com\">www.example.com</a></p>\n");
73+
public void noWwwLinks() {
74+
String html = NO_WWW_RENDERER.render(NO_WWW_PARSER.parse("www.example.com"));
75+
assertThat(html).isEqualTo("<p>www.example.com</p>\n");
7676
}
7777

7878
@Test

0 commit comments

Comments
 (0)