@@ -204,24 +204,42 @@ fn adjust_links<'a>(
204
204
// Fix redirect links
205
205
let normalized_path_split: Vec < & str > = normalized_path. split ( '#' ) . collect ( ) ;
206
206
for ( original, redirect) in & redirects {
207
- if !SCHEME_LINK . is_match ( & redirect)
208
- && normalize_path ( original. trim_start_matches ( '/' ) )
209
- . eq_ignore_ascii_case ( & normalize_path ( normalized_path_split[ 0 ] ) )
207
+ if normalize_path ( original. trim_start_matches ( '/' ) )
208
+ . eq_ignore_ascii_case ( & normalized_path)
209
+ || normalize_path ( original. trim_start_matches ( '/' ) )
210
+ . eq_ignore_ascii_case ( & normalized_path_split[ 0 ] )
210
211
{
211
212
let mut unnormalized_path = String :: new ( ) ;
212
- let base = PathBuf :: from ( normalized_path_split[ 0 ] )
213
- . parent ( )
214
- . expect ( "path can't be empty" )
215
- . to_str ( )
216
- . expect ( "utf-8 paths only" )
217
- . to_owned ( ) ;
218
- write ! ( unnormalized_path, "{}/{}" , normalize_path( base) , redirect)
219
- . unwrap ( ) ;
220
- for i in 1 ..normalized_path_split. len ( ) {
221
- unnormalized_path. push ( '#' ) ;
222
- unnormalized_path. push_str ( normalized_path_split[ i] ) ;
213
+ if SCHEME_LINK . is_match ( & redirect) {
214
+ unnormalized_path = redirect. to_string ( ) ;
215
+ } else {
216
+ let base = PathBuf :: from ( normalized_path_split[ 0 ] )
217
+ . parent ( )
218
+ . expect ( "path can't be empty" )
219
+ . to_str ( )
220
+ . expect ( "utf-8 paths only" )
221
+ . to_owned ( ) ;
222
+ write ! ( unnormalized_path, "{}/{}" , normalize_path( base) , redirect)
223
+ . unwrap ( ) ;
224
+ }
225
+
226
+ // original without anchors, need to append link anchors
227
+ if !original. contains ( "#" ) {
228
+ for i in 1 ..normalized_path_split. len ( ) {
229
+ if !unnormalized_path. contains ( "#" ) {
230
+ unnormalized_path. push ( '#' ) ;
231
+ } else {
232
+ unnormalized_path. push ( '-' ) ;
233
+ }
234
+ unnormalized_path. push_str ( normalized_path_split[ i] ) ;
235
+ }
236
+ }
237
+
238
+ if !SCHEME_LINK . is_match ( & redirect) {
239
+ normalized_path = normalize_path ( unnormalized_path) ;
240
+ } else {
241
+ return CowStr :: from ( unnormalized_path) ;
223
242
}
224
- normalized_path = normalize_path ( unnormalized_path) ;
225
243
break ;
226
244
}
227
245
}
0 commit comments