Non-word boundary Regex on user Mentions (#2096)
* fix: non-word boundary regex on user mentions; show user when mentioned with a path * allow only a single slash after the user
This commit is contained in:
parent
a3e0b6aa9c
commit
9b73990083
@ -6,7 +6,7 @@ import { toString } from 'mdast-util-to-string'
|
||||
const userGroup = '[\\w_]+'
|
||||
const subGroup = '[A-Za-z][\\w_]+'
|
||||
|
||||
const mentionRegex = new RegExp('(?:^|\\s)@(' + userGroup + '(?:\\/' + userGroup + ')?)', 'gi')
|
||||
const mentionRegex = new RegExp('\\B@(' + userGroup + '(?:\\/' + userGroup + ')?)', 'gi')
|
||||
const subRegex = new RegExp('~(' + subGroup + '(?:\\/' + subGroup + ')?)', 'gi')
|
||||
const nostrIdRegex = /\b((npub1|nevent1|nprofile1|note1|naddr1)[02-9ac-hj-np-z]+)\b/g
|
||||
|
||||
@ -116,8 +116,8 @@ export default function rehypeSN (options = {}) {
|
||||
}
|
||||
|
||||
const [fullMatch, mentionMatch, subMatch] = match
|
||||
const replacement = mentionMatch ? replaceMention(fullMatch, mentionMatch) : replaceSub(fullMatch, subMatch)
|
||||
|
||||
const replacement = mentionMatch ? replaceMention(fullMatch, mentionMatch) : replaceSub(fullMatch, subMatch)
|
||||
if (replacement) {
|
||||
newChildren.push(replacement)
|
||||
} else {
|
||||
@ -238,10 +238,11 @@ export default function rehypeSN (options = {}) {
|
||||
}
|
||||
|
||||
function replaceMention (value, username) {
|
||||
// split the name by / to allow user paths and still show the user
|
||||
return {
|
||||
type: 'element',
|
||||
tagName: 'mention',
|
||||
properties: { href: '/' + username, name: username },
|
||||
properties: { href: '/' + username, name: username.split('/')[0] },
|
||||
children: [{ type: 'text', value }]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user