diff --git a/src/lib/components/markdown/renderers/plugins.ts b/src/lib/components/markdown/renderers/plugins.ts index 9c4c1d9d..39dff313 100644 --- a/src/lib/components/markdown/renderers/plugins.ts +++ b/src/lib/components/markdown/renderers/plugins.ts @@ -84,7 +84,9 @@ export const linkify = markedLinkifyIt( }, }, }, - {} + { + fuzzyEmail: false, + } ) const regexes = { @@ -92,12 +94,18 @@ const regexes = { comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/i, user: /^https:\/\/([a-zA-Z0-9.-]+)(\/u\/)([a-zA-Z0-9.-_]+)$/i, community: /^https:\/\/([a-zA-Z0-9.-]+)(\/c\/)([a-zA-Z0-9.-_]+)$/i, + implicitUser: /^mailto:([a-z0-9_\.-]+)@(([\da-z\.-]+)\.([a-z]{2,63}))/i, } /** * Convert links to photon links */ export const photonify = (link: string) => { + if (regexes.community.test(link)) { + const match = link.match(regexes.community) + if (!match) return + return `/c/${match?.[3]}@${match?.[1]}` + } if (regexes.post.test(link)) { const match = link.match(regexes.post) if (!match) return @@ -113,10 +121,11 @@ export const photonify = (link: string) => { if (!match) return return `/u/${match?.[3]}@${match?.[1]}` } - if (regexes.community.test(link)) { - const match = link.match(regexes.community) - if (!match) return - return `/c/${match?.[3]}@${match?.[1]}` + if (regexes.implicitUser.test(link)) { + const exec = regexes.implicitUser.exec(link) + + if (!exec?.[1] || !exec?.[2]) return + return `/u/${exec[1]}@${exec[2]}` } }