@@ -8,7 +8,7 @@ const subGroup = '[A-Za-z][\\w_]+'
8
8
9
9
const mentionRegex = new RegExp ( '\\B@(' + userGroup + '(?:\\/' + userGroup + ')?)' , 'gi' )
10
10
const subRegex = new RegExp ( '~(' + subGroup + '(?:\\/' + subGroup + ')?)' , 'gi' )
11
- const nostrIdRegex = / \b ( ( n p u b 1 | n e v e n t 1 | n p r o f i l e 1 | n o t e 1 | n a d d r 1 ) [ 0 2 - 9 a c - h j - n p - z ] + ) \b / g
11
+ const nostrIdRegex = / \b ( ( n p u b 1 | n e v e n t 1 | n p r o f i l e 1 | n o t e 1 | n a d d r 1 ) [ 0 2 - 9 a c - h j - n p - z ] + ) \b / i
12
12
13
13
export default function rehypeSN ( options = { } ) {
14
14
const { stylers = [ ] } = options
@@ -77,12 +77,20 @@ export default function rehypeSN (options = {}) {
77
77
if ( node . tagName === 'a' &&
78
78
! parent . children . some ( s => s . type === 'text' && s . value . trim ( ) ) &&
79
79
toString ( node ) === node . properties . href ) {
80
- const embed = parseEmbedUrl ( node . properties . href )
81
- if ( embed ) {
82
- node . tagName = 'embed'
83
- node . properties = { ... embed , src : node . properties . href }
84
- } else {
80
+ nostrIdRegex . lastIndex = 0
81
+ const isNostrLink = nostrIdRegex . test ( node . properties . href )
82
+ nostrIdRegex . lastIndex = 0
83
+
84
+ if ( isNostrLink ) {
85
85
node . tagName = 'autolink'
86
+ } else {
87
+ const embed = parseEmbedUrl ( node . properties . href )
88
+ if ( embed ) {
89
+ node . tagName = 'embed'
90
+ node . properties = { ...embed , src : node . properties . href }
91
+ } else {
92
+ node . tagName = 'autolink'
93
+ }
86
94
}
87
95
}
88
96
@@ -137,7 +145,7 @@ export default function rehypeSN (options = {}) {
137
145
}
138
146
139
147
// Handle Nostr IDs
140
- if ( node . type === 'text' ) {
148
+ if ( node . type === 'text' && ! ( parent && [ 'a' , 'autolink' ] . includes ( parent . tagName ) ) ) {
141
149
const newChildren = [ ]
142
150
let lastIndex = 0
143
151
let match
0 commit comments