Skip to content

Commit e039a31

Browse files
committed
Fix(npub): Do not parse npubs in links
1 parent 8337aad commit e039a31

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/rehype-sn.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const subGroup = '[A-Za-z][\\w_]+'
88

99
const mentionRegex = new RegExp('\\B@(' + userGroup + '(?:\\/' + userGroup + ')?)', 'gi')
1010
const subRegex = new RegExp('~(' + subGroup + '(?:\\/' + subGroup + ')?)', 'gi')
11-
const nostrIdRegex = /\b((npub1|nevent1|nprofile1|note1|naddr1)[02-9ac-hj-np-z]+)\b/g
11+
const nostrIdRegex = /\b((npub1|nevent1|nprofile1|note1|naddr1)[02-9ac-hj-np-z]+)\b/i
1212

1313
export default function rehypeSN (options = {}) {
1414
const { stylers = [] } = options
@@ -78,7 +78,7 @@ export default function rehypeSN (options = {}) {
7878
!parent.children.some(s => s.type === 'text' && s.value.trim()) &&
7979
toString(node) === node.properties.href) {
8080
const embed = parseEmbedUrl(node.properties.href)
81-
if (embed) {
81+
if (embed && !nostrIdRegex.test(node.properties.href)) {
8282
node.tagName = 'embed'
8383
node.properties = { ...embed, src: node.properties.href }
8484
} else {
@@ -137,7 +137,7 @@ export default function rehypeSN (options = {}) {
137137
}
138138

139139
// Handle Nostr IDs
140-
if (node.type === 'text') {
140+
if (node.type === 'text' && !(parent && ['a', 'autolink'].includes(parent.tagName))) {
141141
const newChildren = []
142142
let lastIndex = 0
143143
let match

0 commit comments

Comments
 (0)