fix URL parsing edge cases (#360)

This should fix the following:
- URLs in parentheses
- URLs at the end of a sentence
This commit is contained in:
Sam Samskies
2023-02-27 09:21:38 -10:00
committed by GitHub
parent f934dcd092
commit 2782f24690
4 changed files with 50 additions and 10 deletions

View File

@ -4,8 +4,8 @@ import { Link } from "react-router-dom";
import ReactMarkdown from "react-markdown";
import { visit, SKIP } from "unist-util-visit";
import { UrlRegex, MentionRegex, InvoiceRegex, HashtagRegex } from "Const";
import { eventLink, hexToBech32, unwrap } from "Util";
import { MentionRegex, InvoiceRegex, HashtagRegex } from "Const";
import { eventLink, hexToBech32, splitByUrl, unwrap } from "Util";
import Invoice from "Element/Invoice";
import Hashtag from "Element/Hashtag";
@ -36,7 +36,7 @@ export default function Text({ content, tags, creator, users }: TextProps) {
return fragments
.map(f => {
if (typeof f === "string") {
return f.split(UrlRegex).map(a => {
return splitByUrl(f).map(a => {
if (a.startsWith("http")) {
return <HyperText key={a} link={a} creator={creator} />;
}