diff --git a/pkg/interface/src/logic/lib/tokenizeMessage.js b/pkg/interface/src/logic/lib/tokenizeMessage.js index 19f2313166..84c25492ea 100644 --- a/pkg/interface/src/logic/lib/tokenizeMessage.js +++ b/pkg/interface/src/logic/lib/tokenizeMessage.js @@ -1,7 +1,7 @@ import urbitOb from 'urbit-ob'; import { parsePermalink, permalinkToReference } from '~/logic/lib/permalinks'; -const URL_REGEX = new RegExp(String(/^([^[\]]*?)(([\w\-\+]+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+[-a-zA-Z0-9:@;?&=\/%\+\*!'\(\)\$_\{\}\^~\[\]`#|])([\s\S]*)/.source)); +const URL_REGEX = new RegExp(String(/^([\s\S]*?)(([\w\-\+]+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+[-a-zA-Z0-9:@;?&=\/%\+\*!'\(\)\$_\{\}\^~\[\]`#|])([\s\S]*)/.source)); const PATP_REGEX = /^([\s\S]*?)(~[a-z_-]+)([\s\S]*)/; @@ -18,7 +18,15 @@ export const isUrl = (str) => { }; const raceRegexes = (str) => { - const link = str.match(URL_REGEX); + let link = str.match(URL_REGEX); + while(link?.[1]?.endsWith('(')) { + const resumePos = link[1].length + link[2].length; + const resume = str.slice(resumePos); + link = resume.match(URL_REGEX); + if(link) { + link[1] = str.slice(0, resumePos) + link[1]; + } + } const groupRef = str.match(GROUP_REGEX); const mention = str.match(PATP_REGEX); let pfix = str; diff --git a/pkg/interface/src/logic/lib/tokenizeMessage.test.js b/pkg/interface/src/logic/lib/tokenizeMessage.test.js index e65f139d1c..2ddb4c1f66 100644 --- a/pkg/interface/src/logic/lib/tokenizeMessage.test.js +++ b/pkg/interface/src/logic/lib/tokenizeMessage.test.js @@ -127,5 +127,15 @@ describe('tokenizeMessage', () => { expect(text).toBe('oh no, '); expect(reference.group).toBe('/ship/~sampel/group-123-abc'); }); + it('should handle permalinks after inline urls', () => { + const example = 'test [test](https://tlon.io) web+urbitgraph://group/~middev/the-forge/graph/~littel-wolfur/writs-7082/170141184505164612398001831549075456000/2/170141184505164722986064231401764421632'; + + const [{ text }, { reference: { graph } }] = tokenizeMessage(example); + + expect(text).toBe('test [test](https://tlon.io) '); + expect(graph.group).toBe('/ship/~middev/the-forge'); + expect(graph.graph).toBe('/ship/~littel-wolfur/writs-7082'); + expect(graph.index).toBe('/170141184505164612398001831549075456000/2/170141184505164722986064231401764421632'); + }); });