react-native-parsed-text icon indicating copy to clipboard operation
react-native-parsed-text copied to clipboard

URL parser with single quote not working

Open pierroo opened this issue 2 years ago • 3 comments

I just realized the url parser would stop the link parsing as soon as there is a single quote.

I got surprised, but it was brought to my attention by a user using this example: https://en.wikipedia.org/wiki/Witold's_Report

it will stop at Witold and the rest won't be caught

pierroo avatar Feb 07 '23 11:02 pierroo

@pierroo you can use Telegram's regex

https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/src/main/java/org/telegram/messenger/LinkifyPort.java

hantrungkien avatar Apr 11 '23 16:04 hantrungkien

Thank you for sharing @hantrungkien , that's quite a wild one! :D Not sure though how to compile it all into a single javascript regex that could trigger parsedText

pierroo avatar Apr 11 '23 16:04 pierroo

@pierroo I'm sure for work. Just convert to regex for javascript and change a little bit and use

const PROTOCOL = '(?:http|https|ton|tg):\\/\\/';
const LABEL_CHAR = 'a-zA-Z0-9';
{
            pattern: new RegExp(WEB_URL, 'gim'),
            style: {color: 'blue', textDecorationLine: 'underline'},
            onPress: (text, index) => {
              console.log(`url = ${text}, index = ${index}`);
            },
}

IMG_9061

hantrungkien avatar Apr 11 '23 16:04 hantrungkien