Low-level link (text, URLs, emails, phone numbers, user tags) parsing library in Dart.
Required Dart >=2.12 (has null-safety support).
Install by adding this package to your pubspec.yaml:
dependencies:
linkify: ^5.0.0import 'package:linkify/linkify.dart';
linkify("Made by https://cretezy.com [email protected]");
// Output: [TextElement: 'Made by ', UrlElement: 'https://cretezy.com' (cretezy.com), TextElement: ' ', EmailElement: '[email protected]' ([email protected])]You can pass LinkifyOptions to the linkify method to change the humanization of URLs (turning https://example.com to example.com):
linkify("https://cretezy.com");
// [UrlElement: 'https://cretezy.com' (cretezy.com)]
linkify("https://cretezy.com", options: LinkifyOptions(humanize: false));
// [UrlElement: 'https://cretezy.com' (https://cretezy.com)]humanize: Removes http/https from shown URLsremoveWww: Removeswww.from shown URLslooseUrl: Enables loose URL parsing (should parse most URLs such asabc.com/xyz)defaultToHttps: When used with [looseUrl], default tohttpsinstead ofhttp
excludeLastPeriod: Excludes.at end of URLs
You can pass linkifiers to linkify as such:
linkify("@cretezy", linkifiers: [UserTagLinkifier()]);Available linkifiers:
EmailLinkifierUrlLinkifierPhoneNumberLinkifierUserTagLinkifier
You can write custom linkifiers for phone numbers or other types of links. Look at the URL linkifier for an example.
This is the flow:
- Calls
parsein the linkifier with a list ofLinkifyElement. This starts as[TextElement(text)] - Your parsers then splits each element into it's parts. For example,
[TextElement("Hello https://example.com")]would become[TextElement("Hello "), UrlElement("https://example.com")] - Each parsers is ran in order of how they are passed to the main
linkifyfunction. By default, this is URL and email linkifiers