diff --git a/packages/linkifyjs/src/parser.js b/packages/linkifyjs/src/parser.js index e135407..1f4d6fd 100644 --- a/packages/linkifyjs/src/parser.js +++ b/packages/linkifyjs/src/parser.js @@ -55,6 +55,7 @@ export function init({ groups }) { tk.CLOSEBRACE, tk.CLOSEBRACKET, tk.CLOSEPAREN, + tk.FULLWIDTH_CLOSEPAREN, tk.COLON, tk.COMMA, tk.DOT, @@ -63,6 +64,7 @@ export function init({ groups }) { tk.OPENBRACE, tk.OPENBRACKET, tk.OPENPAREN, + tk.FULLWIDTH_OPENPAREN, tk.QUERY, tk.QUOTE, tk.SEMI @@ -209,17 +211,20 @@ export function init({ groups }) { const UrlOpenbracket = tt(Url, tk.OPENBRACKET); // URL followed by [ const UrlOpenanglebracket = tt(Url, tk.OPENANGLEBRACKET); // URL followed by < const UrlOpenparen = tt(Url, tk.OPENPAREN); // URL followed by ( + const UrlFullwidthOpenparen = tt(Url, tk.FULLWIDTH_OPENPAREN); // URL followed by ( tt(UrlNonaccept, tk.OPENBRACE, UrlOpenbrace); tt(UrlNonaccept, tk.OPENBRACKET, UrlOpenbracket); tt(UrlNonaccept, tk.OPENANGLEBRACKET, UrlOpenanglebracket); tt(UrlNonaccept, tk.OPENPAREN, UrlOpenparen); + tt(UrlNonaccept, tk.FULLWIDTH_OPENPAREN, UrlFullwidthOpenparen); // Closing bracket component. This character WILL be included in the URL tt(UrlOpenbrace, tk.CLOSEBRACE, Url); tt(UrlOpenbracket, tk.CLOSEBRACKET, Url); tt(UrlOpenanglebracket, tk.CLOSEANGLEBRACKET, Url); tt(UrlOpenparen, tk.CLOSEPAREN, Url); + tt(UrlFullwidthOpenparen, tk.FULLWIDTH_CLOSEPAREN, Url); tt(UrlOpenbrace, tk.CLOSEBRACE, Url); // URL that beings with an opening bracket, followed by a symbols. @@ -229,48 +234,58 @@ export function init({ groups }) { const UrlOpenbracketQ = makeState(mtk.Url); // URL followed by [ and some symbols that the URL can end it const UrlOpenanglebracketQ = makeState(mtk.Url); // URL followed by < and some symbols that the URL can end it const UrlOpenparenQ = makeState(mtk.Url); // URL followed by ( and some symbols that the URL can end it + const UrlFullwidthOpenparenQ = makeState(mtk.Url); // URL followed by ( and some symbols that the URL can end it ta(UrlOpenbrace, qsAccepting, UrlOpenbraceQ); ta(UrlOpenbracket, qsAccepting, UrlOpenbracketQ); ta(UrlOpenanglebracket, qsAccepting, UrlOpenanglebracketQ); ta(UrlOpenparen, qsAccepting, UrlOpenparenQ); + ta(UrlFullwidthOpenparen, qsAccepting, UrlFullwidthOpenparenQ); const UrlOpenbraceSyms = makeState(); // UrlOpenbrace followed by some symbols it cannot end it const UrlOpenbracketSyms = makeState(); // UrlOpenbracketQ followed by some symbols it cannot end it const UrlOpenanglebracketSyms = makeState(); // UrlOpenanglebracketQ followed by some symbols it cannot end it const UrlOpenparenSyms = makeState(); // UrlOpenparenQ followed by some symbols it cannot end it + const UrlFullwidthOpenparenSyms = makeState(); // UrlFullwidthOpenparenQ followed by some symbols it cannot end it ta(UrlOpenbrace, qsNonAccepting); ta(UrlOpenbracket, qsNonAccepting); ta(UrlOpenanglebracket, qsNonAccepting); ta(UrlOpenparen, qsNonAccepting); + ta(UrlFullwidthOpenparen, qsNonAccepting); // URL that begins with an opening bracket, followed by some symbols ta(UrlOpenbraceQ, qsAccepting, UrlOpenbraceQ); ta(UrlOpenbracketQ, qsAccepting, UrlOpenbracketQ); ta(UrlOpenanglebracketQ, qsAccepting, UrlOpenanglebracketQ); ta(UrlOpenparenQ, qsAccepting, UrlOpenparenQ); + ta(UrlFullwidthOpenparenQ, qsAccepting, UrlFullwidthOpenparenQ); ta(UrlOpenbraceQ, qsNonAccepting, UrlOpenbraceQ); ta(UrlOpenbracketQ, qsNonAccepting, UrlOpenbracketQ); ta(UrlOpenanglebracketQ, qsNonAccepting, UrlOpenanglebracketQ); ta(UrlOpenparenQ, qsNonAccepting, UrlOpenparenQ); + ta(UrlFullwidthOpenparenQ, qsAccepting, UrlFullwidthOpenparenQ); ta(UrlOpenbraceSyms, qsAccepting, UrlOpenbraceSyms); ta(UrlOpenbracketSyms, qsAccepting, UrlOpenbracketQ); ta(UrlOpenanglebracketSyms, qsAccepting, UrlOpenanglebracketQ); ta(UrlOpenparenSyms, qsAccepting, UrlOpenparenQ); + ta(UrlFullwidthOpenparenSyms, qsAccepting, UrlFullwidthOpenparenQ); ta(UrlOpenbraceSyms, qsNonAccepting, UrlOpenbraceSyms); ta(UrlOpenbracketSyms, qsNonAccepting, UrlOpenbracketSyms); ta(UrlOpenanglebracketSyms, qsNonAccepting, UrlOpenanglebracketSyms); ta(UrlOpenparenSyms, qsNonAccepting, UrlOpenparenSyms); + ta(UrlFullwidthOpenparenSyms, qsAccepting, UrlFullwidthOpenparenSyms); // Close brace/bracket to become regular URL tt(UrlOpenbracketQ, tk.CLOSEBRACKET, Url); tt(UrlOpenanglebracketQ, tk.CLOSEANGLEBRACKET, Url); tt(UrlOpenparenQ, tk.CLOSEPAREN, Url); + tt(UrlFullwidthOpenparenQ, tk.FULLWIDTH_CLOSEPAREN, Url); tt(UrlOpenbraceQ, tk.CLOSEBRACE, Url); tt(UrlOpenbracketSyms, tk.CLOSEBRACKET, Url); tt(UrlOpenanglebracketSyms, tk.CLOSEANGLEBRACKET, Url); - tt(UrlOpenparenSyms, tk.CLOSEPAREN, Url); + tt(UrlFullwidthOpenparenSyms, tk.FULLWIDTH_CLOSEPAREN, Url); tt(UrlOpenbraceSyms, tk.CLOSEPAREN, Url); + tt(UrlOpenbraceSyms, tk.FULLWIDTH_CLOSEPAREN, Url); tt(Start, tk.LOCALHOST, DomainDotTld); // localhost is a valid URL state tt(Start, tk.NL, mtk.Nl); // single new line diff --git a/packages/linkifyjs/src/scanner.js b/packages/linkifyjs/src/scanner.js index 1cbae36..80d650a 100644 --- a/packages/linkifyjs/src/scanner.js +++ b/packages/linkifyjs/src/scanner.js @@ -58,10 +58,12 @@ export function init(customSchemes = []) { tt(Start, '[', tk.OPENBRACKET); tt(Start, '<', tk.OPENANGLEBRACKET); tt(Start, '(', tk.OPENPAREN); + tt(Start, '(', tk.FULLWIDTH_OPENPAREN); tt(Start, '}', tk.CLOSEBRACE); tt(Start, ']', tk.CLOSEBRACKET); tt(Start, '>', tk.CLOSEANGLEBRACKET); tt(Start, ')', tk.CLOSEPAREN); + tt(Start, ')', tk.FULLWIDTH_CLOSEPAREN); tt(Start, '&', tk.AMPERSAND); tt(Start, '*', tk.ASTERISK); tt(Start, '@', tk.AT); diff --git a/packages/linkifyjs/src/text.js b/packages/linkifyjs/src/text.js index 8b4a595..f3dd9ab 100644 --- a/packages/linkifyjs/src/text.js +++ b/packages/linkifyjs/src/text.js @@ -44,6 +44,8 @@ export const CLOSEBRACE = 'CLOSEBRACE'; // } export const CLOSEBRACKET = 'CLOSEBRACKET'; // ] export const CLOSEANGLEBRACKET = 'CLOSEANGLEBRACKET'; // > export const CLOSEPAREN = 'CLOSEPAREN'; // ) +export const FULLWIDTH_OPENPAREN = 'FULLWIDTH_OPENPAREN'; // ( +export const FULLWIDTH_CLOSEPAREN = 'FULLWIDTH_CLOSEPAREN'; // ) // Various symbols export const AMPERSAND = 'AMPERSAND'; // & diff --git a/test/spec/linkifyjs/parser.test.js b/test/spec/linkifyjs/parser.test.js index ee12d75..5346b89 100644 --- a/test/spec/linkifyjs/parser.test.js +++ b/test/spec/linkifyjs/parser.test.js @@ -272,6 +272,14 @@ const tests = [ 'This Url www.drive1.com with www and digits also www.500px.com', [Text, Url, Text, Url], ['This Url ', 'www.drive1.com', ' with www and digits also ', 'www.500px.com'] + ], [ + 'Link 1(http://foo.com/blah_blah) Link 2(http://foo.com/blah_blah_(wikipedia)_(again))', + [Text, Url, Text, Url, Text], + ['Link 1(', 'http://foo.com/blah_blah', ') Link 2(', 'http://foo.com/blah_blah_(wikipedia)_(again)', ')'] + ], [ + 'Link 1(http://foo.com/blah_blah) Link 2(http://foo.com/blah_blah_(wikipedia)_(again))', + [Text, Url, Text, Url, Text], + ['Link 1(', 'http://foo.com/blah_blah', ') Link 2(', 'http://foo.com/blah_blah_(wikipedia)_(again)', ')'] ], ];