Skip to content

Commit

Permalink
#117 fix regex on clickable url match
Browse files Browse the repository at this point in the history
  • Loading branch information
balzack committed Oct 22, 2024
1 parent 0ad9969 commit b49b22e
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,14 @@ export function useTopicItem(item, hosting, remove, contentKey) {
};

const clickableText = (text) => {
const urlPatternn = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator

const urlPattern = new RegExp('(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)');
const hostPattern = new RegExp('^https?:\\/\\/', 'i');

let clickable = [];
let group = '';
const words = text == null ? [''] : text.split(' ');
words.forEach((word, index) => {
if (!!urlPatternn.test(word)) {
if (!!urlPattern.test(word)) {
clickable.push(<Text key={index}>{ group }</Text>);
group = '';
const url = !!hostPattern.test(word) ? word : `https://${word}`;
Expand Down

0 comments on commit b49b22e

Please sign in to comment.