Skip to content

Commit

Permalink
Fix boundaries around mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Nov 21, 2024
1 parent 09bacdc commit 88b2a48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api/paidAction/lib/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { deleteReminders, getDeleteAt, getRemindAt } from '@/lib/item'
import { parseInternalLinks } from '@/lib/url'

export async function getMentions ({ text }, { me, tx }) {
const mentionPattern = /\B@[\w_]+/gi
// match any "@username" at start of line / with leading whitespace or end of line / with trailing whitespace
// ( trailing paths like "@username/all" are also matched with a non-capturing group )
const mentionPattern = /(?<=\s|^)@([\w_]+(?:\/[\w_]+)?)(?=\s|$)/gi
const names = text.match(mentionPattern)?.map(m => m.slice(1))
if (names?.length > 0) {
const users = await tx.user.findMany({
Expand Down
3 changes: 1 addition & 2 deletions lib/rehype-sn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { parseEmbedUrl, parseInternalLinks } from './url'
import { slug } from 'github-slugger'
import { toString } from 'mdast-util-to-string'

const userGroup = '[\\w_]+'
const subGroup = '[A-Za-z][\\w_]+'

const mentionRegex = new RegExp('@(' + userGroup + '(?:\\/' + userGroup + ')?)', 'gi')
const mentionRegex = /(?<=\s|^)@([\w_]+(?:\/[\w_]+)?)(?=\s|$)/gi
const subRegex = new RegExp('~(' + subGroup + '(?:\\/' + subGroup + ')?)', 'gi')
const nostrIdRegex = /\b((npub1|nevent1|nprofile1|note1|naddr1)[02-9ac-hj-np-z]+)\b/g

Expand Down

0 comments on commit 88b2a48

Please sign in to comment.