From a2e4893be89d0f5d5f88993306b5a2f83fa3f308 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Wed, 16 Feb 2022 10:32:44 -0800 Subject: [PATCH] Don't include trailing !:,.; in links --- web/components/linkify.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/components/linkify.tsx b/web/components/linkify.tsx index a1b617ad..21567b59 100644 --- a/web/components/linkify.tsx +++ b/web/components/linkify.tsx @@ -2,9 +2,11 @@ import { Fragment } from 'react' import { SiteLink } from './site-link' // Return a JSX span, linkifying @username, #hashtags, and https://... +// TODO: Use a markdown parser instead of rolling our own here. export function Linkify(props: { text: string; gray?: boolean }) { const { text, gray } = props - const regex = /(?:^|\s)(?:[@#][a-z0-9_]+|https?:\/\/\S+)/gi + const regex = + /(?:^|\s)(?:[@#][a-z0-9_]+|https?:\/\/[-A-Za-z0-9+&@#\/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#\/%=~_()|])/gi const matches = text.match(regex) || [] const links = matches.map((match) => { // Matches are in the form: " @username" or "https://example.com"