1- import 'package:flutter/widgets .dart' show immutable ;
1+ import 'package:meta/meta .dart' ;
22
33import '../../quill_delta.dart' ;
44import '../common/extensions/uri_ext.dart' ;
@@ -362,24 +362,38 @@ class AutoFormatMultipleLinksRule extends InsertRule {
362362 // https://example.net/
363363 // URL generator tool (https://www.randomlists.com/urls) is used.
364364
365- static const _oneLineLinkPattern =
366- r'^https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?([\/\?#].*)?$' ;
367- static const _detectLinkPattern =
368- r'https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?([\/\?#][^\s]*)?' ;
369-
370- /// It requires a valid link in one link
371- RegExp get oneLineLinkRegExp => RegExp (
372- _oneLineLinkPattern,
365+ /// A regular expression to match a single-line URL
366+ @internal
367+ static RegExp get singleLineUrlRegExp => RegExp (
368+ r'^https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?([\/\?#].*)?$' ,
373369 caseSensitive: false ,
374370 );
375371
376- /// It detect if there is a link in the text whatever if it in the middle etc
377- // Used to solve bug https://github.com/singerdmx/flutter-quill/issues/1432
378- RegExp get detectLinkRegExp => RegExp (
379- _detectLinkPattern,
372+ /// A regular expression to detect a URL anywhere in the text, even if it's in the middle of other content.
373+ /// Used to resolve bug https://github.com/singerdmx/flutter-quill/issues/1432
374+ @internal
375+ static RegExp get urlInTextRegExp => RegExp (
376+ r'https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?([\/\?#][^\s]*)?' ,
380377 caseSensitive: false ,
381378 );
382- RegExp get linkRegExp => oneLineLinkRegExp;
379+
380+ @Deprecated (
381+ 'Deprecated and will be removed in future-releasese as this is not the place to store regex.\n '
382+ 'Please use a custom regex instead or use AutoFormatMultipleLinksRule.singleLineUrlRegExp which is an internal API.' ,
383+ )
384+ RegExp get oneLineLinkRegExp => singleLineUrlRegExp;
385+
386+ @Deprecated (
387+ 'Deprecated and will be removed in future-releasese as this is not the place to store regex.\n '
388+ 'Please use a custom regex instead or use AutoFormatMultipleLinksRule.urlInTextRegExp which is an internal API.' ,
389+ )
390+ RegExp get detectLinkRegExp => urlInTextRegExp;
391+
392+ @Deprecated (
393+ 'No longer used and will be silently ignored. Please use custom regex '
394+ 'or use AutoFormatMultipleLinksRule.singleLineUrlRegExp which is an internal API.' ,
395+ )
396+ RegExp get linkRegExp => singleLineUrlRegExp;
383397
384398 @override
385399 Delta ? applyRule (
@@ -388,6 +402,8 @@ class AutoFormatMultipleLinksRule extends InsertRule {
388402 int ? len,
389403 Object ? data,
390404 Attribute ? attribute,
405+ @Deprecated (
406+ 'No longer used and will be silently ignored and removed in future releases.' )
391407 Object ? extraData,
392408 }) {
393409 // Only format when inserting text.
@@ -423,27 +439,8 @@ class AutoFormatMultipleLinksRule extends InsertRule {
423439 // Build the segment of affected words.
424440 final affectedWords = '$leftWordPart $data $rightWordPart ' ;
425441
426- var usedRegExp = detectLinkRegExp;
427- final alternativeLinkRegExp = extraData;
428- if (alternativeLinkRegExp != null ) {
429- try {
430- if (alternativeLinkRegExp is ! String ) {
431- throw ArgumentError .value (
432- alternativeLinkRegExp,
433- 'alternativeLinkRegExp' ,
434- '`alternativeLinkRegExp` should be of type String' ,
435- );
436- }
437- final regPattern = alternativeLinkRegExp;
438- usedRegExp = RegExp (
439- regPattern,
440- caseSensitive: false ,
441- );
442- } catch (_) {}
443- }
444-
445442 // Check for URL pattern.
446- final matches = usedRegExp .allMatches (affectedWords);
443+ final matches = urlInTextRegExp .allMatches (affectedWords);
447444
448445 // If there are no matches, do not apply any format.
449446 if (matches.isEmpty) return null ;
0 commit comments