Skip to content

Commit

Permalink
Fixed Cretezy#9 before v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Cretezy committed Mar 18, 2019
1 parent 948704b commit ae25194
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## [2.0.0] - 2019-03-17

- Add email address linking (thanks [PieterAelse](https://github.com/PieterAelse)! [#8](https://github.com/Cretezy/flutter_linkify/pull/8)).
- Change API to pass a `LinkableElement` to the `onOpen` callback:
- Breaking: Change API to pass a `LinkableElement` to the `onOpen` callback:
- Accessing the URL can be done by using `link.url`.
- You can check using `is` if it is a `LinkElement` or `EmailElement` for custom handling.
- Added `linkTypes` option to enable/disable parsing URLs/emails.
- More line break fixes (should be the last! [#9](https://github.com/Cretezy/flutter_linkify/issues/9))

## [1.1.1] - 2019-03-03

Expand Down
11 changes: 6 additions & 5 deletions lib/linkify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ class TextElement extends LinkifyElement {
}

final _linkifyUrlRegex = RegExp(
r"(\n*?.*?\s*?)((?:https?):\/\/[^\s/$.?#].[^\s]*)",
r"^((?:.|\n)*?)((?:https?):\/\/[^\s/$.?#].[^\s]*)",
caseSensitive: false,
);

final _linkifyEmailRegex = RegExp(
r"(\n*?.*?\s*?)((mailto:)?[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})",
caseSensitive: false);
r"^((?:.|\n)*?)((mailto:)?[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})",
caseSensitive: false,
);

/// Turns [text] into a list of [LinkifyElement]
///
Expand Down Expand Up @@ -93,7 +94,7 @@ List<LinkifyElement> linkify(
list.add(TextElement(text));
} else {
if (urlMatch != null) {
text = text.replaceFirst(_linkifyUrlRegex, "");
text = text.replaceFirst(urlMatch.group(0), "");

if (urlMatch.group(1).isNotEmpty) {
list.add(TextElement(urlMatch.group(1)));
Expand All @@ -110,7 +111,7 @@ List<LinkifyElement> linkify(
}
}
} else if (emailMatch != null) {
text = text.replaceFirst(_linkifyEmailRegex, "");
text = text.replaceFirst(emailMatch.group(0), "");

if (emailMatch.group(1).isNotEmpty) {
list.add(TextElement(emailMatch.group(1)));
Expand Down

0 comments on commit ae25194

Please sign in to comment.