@@ -145,23 +145,29 @@ require(["core/pubsubhub"], (respecEvents) => {
145
145
require ( [ "core/pubsubhub" ] , ( respecEvents ) => {
146
146
"use strict" ;
147
147
respecEvents . sub ( 'beforesave' , ( documentElement ) => {
148
- $ ( "a[href]" , documentElement ) . each ( ( index ) => {
149
- // Don't rewrite these.
150
- if ( $ ( this , documentElement ) . closest ( 'dd' ) . prev ( ) . text ( ) . match ( / L a t e s t e d i t o r | T e s t s u i t e | I m p l e m e n t a t i o n r e p o r t / ) ) return ;
151
- if ( $ ( this , documentElement ) . closest ( 'section.preserve' ) . length > 0 ) return ;
148
+ for ( const anchor of document . querySelectorAll ( "a[href]" ) ) {
149
+ const dd = anchor . closest ( 'dd' ) ;
150
+
151
+ // Don't replace specific anchors
152
+ if ( dd ) {
153
+ const dt = dd . previousElementSibling ;
154
+ if ( dt . textContent . match ( / L a t e s t e d i t o r | T e s t s u i t e | I m p l e m e n t a t i o n r e p o r t / ) ) return ;
155
+ }
156
+ if ( anchor . closest ( 'section.preserve' ) ) return ;
157
+
158
+ if ( anchor . href === undefined ) return ;
152
159
153
- const href = $ ( this , documentElement ) . attr ( "href" ) ;
154
160
for ( const toReplace in jsonld . conversions ) {
155
- if ( href . indexOf ( toReplace ) !== - 1 ) {
161
+ if ( anchor . href . indexOf ( toReplace ) !== - 1 ) {
156
162
const replacement = jsonld . conversions [ toReplace ] ;
157
- const newHref = href . replace ( toReplace , replacement ) ;
158
- $ ( this , documentElement ) . attr ( " href" , newHref ) ;
159
- if ( $ ( this , documentElement ) . text ( ) . indexOf ( toReplace ) !== - 1 ) {
160
- $ ( this , documentElement ) . text ( $ ( this , documentElement ) . text ( ) . replace ( toReplace , replacement ) ) ;
163
+ const newHref = anchor . href . replace ( toReplace , replacement ) ;
164
+ anchor . setAttribute ( ' href' , newHref ) ;
165
+ if ( anchor . textContent ( ) . indexOf ( toReplace ) !== - 1 ) {
166
+ anchor . innerText = anchor . textContent ( ) . replace ( toReplace , replacement ) ;
161
167
}
162
168
}
163
169
}
164
- } ) ;
170
+ }
165
171
} ) ;
166
172
} ) ;
167
173
0 commit comments