@@ -73,16 +73,38 @@ export default function rehypeSN (options = {}) {
73
73
}
74
74
}
75
75
76
- // only show a link as an embed if it doesn't have text siblings
77
- if ( node . tagName === 'a' &&
78
- ! parent . children . some ( s => s . type === 'text' && s . value . trim ( ) ) &&
79
- toString ( node ) === node . properties . href ) {
80
- const embed = parseEmbedUrl ( node . properties . href )
81
- if ( embed ) {
76
+ if ( node . tagName === 'a' ) {
77
+ const href = node . properties . href
78
+ const textOnly = toString ( node ) === href
79
+ const hasTextSibling = parent . children . some (
80
+ s => s . type === 'text' && s . value . trim ( )
81
+ )
82
+
83
+ let embed , host
84
+ try {
85
+ embed = parseEmbedUrl ( href )
86
+ } catch {
87
+ embed = null
88
+ }
89
+ try {
90
+ host = new URL ( href ) . hostname
91
+ } catch {
92
+ host = null
93
+ }
94
+
95
+ if ( embed ?. provider === 'nostr' && host === 'njump.me' ) {
96
+ node . tagName = 'embed'
97
+ node . properties = { ...embed , src : href }
98
+ return
99
+ }
100
+ if ( embed && embed . provider !== 'nostr' && textOnly && ! hasTextSibling ) {
82
101
node . tagName = 'embed'
83
- node . properties = { ...embed , src : node . properties . href }
84
- } else {
102
+ node . properties = { ...embed , src : href }
103
+ return
104
+ }
105
+ if ( textOnly && ! hasTextSibling ) {
85
106
node . tagName = 'autolink'
107
+ return
86
108
}
87
109
}
88
110
@@ -136,8 +158,7 @@ export default function rehypeSN (options = {}) {
136
158
}
137
159
}
138
160
139
- // Handle Nostr IDs
140
- if ( node . type === 'text' ) {
161
+ if ( node . type === 'text' && ! [ 'a' , 'autolink' ] . includes ( parent ?. tagName ) ) {
141
162
const newChildren = [ ]
142
163
let lastIndex = 0
143
164
let match
@@ -146,9 +167,7 @@ export default function rehypeSN (options = {}) {
146
167
if ( lastIndex < match . index ) {
147
168
newChildren . push ( { type : 'text' , value : node . value . slice ( lastIndex , match . index ) } )
148
169
}
149
-
150
170
newChildren . push ( replaceNostrId ( match [ 0 ] , match [ 0 ] ) )
151
-
152
171
lastIndex = nostrIdRegex . lastIndex
153
172
}
154
173
0 commit comments