Revert "Fix hyperlinks when starting with an open paren"

This reverts commit 2fd9759bc1.
This commit is contained in:
James Grugett 2022-05-11 21:42:33 -04:00
parent 1063897c7c
commit 696e6a7882

View File

@ -6,21 +6,22 @@ import { SiteLink } from './site-link'
export function Linkify(props: { text: string; gray?: boolean }) {
const { text, gray } = props
const regex =
/(?<=^|\s|\()(?:[@#][a-z0-9_]+|https?:\/\/[-A-Za-z0-9+&@#\/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#\/%=~_|])/gi
/(?:^|\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"
const symbol = match.substring(0, 1)
const tag = match.substring(1)
const whitespace = match.match(/^\s/)
const symbol = match.trim().substring(0, 1)
const tag = match.trim().substring(1)
const href =
{
'@': `/${tag}`,
'#': `/tag/${tag}`,
}[symbol] ?? match
}[symbol] ?? match.trim()
return (
<>
{whitespace}
<SiteLink
className={gray ? 'text-gray-500' : 'text-indigo-700'}
href={href}