@@ -146,7 +146,7 @@ pub fn normalize_path_id(mut path: String) -> String {
146
146
fn adjust_links < ' a > (
147
147
event : Event < ' a > ,
148
148
path : Option < & Path > ,
149
- redirects : HashMap < String , String > ,
149
+ redirects : & HashMap < String , String > ,
150
150
) -> Event < ' a > {
151
151
static SCHEME_LINK : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"^[a-z][a-z0-9+.-]*:" ) . unwrap ( ) ) ;
152
152
static HTML_MD_LINK : Lazy < Regex > =
@@ -176,14 +176,14 @@ fn adjust_links<'a>(
176
176
fn fix_a_links < ' a > (
177
177
dest : CowStr < ' a > ,
178
178
path : Option < & Path > ,
179
- redirects : HashMap < String , String > ,
179
+ redirects : & HashMap < String , String > ,
180
180
) -> CowStr < ' a > {
181
181
if dest. starts_with ( '#' ) {
182
182
// Fragment-only link.
183
183
if let Some ( path) = path {
184
184
let mut base = path. display ( ) . to_string ( ) ;
185
185
if base. ends_with ( ".md" ) {
186
- base. replace_range ( base. len ( ) - 3 .. , "" ) ;
186
+ base. truncate ( base. len ( ) - 3 ) ;
187
187
}
188
188
return format ! (
189
189
"#{}{}" ,
@@ -228,7 +228,7 @@ fn adjust_links<'a>(
228
228
if let Some ( _) = path {
229
229
// Fix redirect links
230
230
let normalized_path_split: Vec < & str > = normalized_path. split ( '#' ) . collect ( ) ;
231
- for ( original, redirect) in & redirects {
231
+ for ( original, redirect) in redirects {
232
232
if normalize_path ( original. trim_start_matches ( '/' ) )
233
233
. eq_ignore_ascii_case ( & normalized_path)
234
234
|| normalize_path ( original. trim_start_matches ( '/' ) )
@@ -295,7 +295,7 @@ fn adjust_links<'a>(
295
295
fn fix_html < ' a > (
296
296
html : CowStr < ' a > ,
297
297
path : Option < & Path > ,
298
- redirects : HashMap < String , String > ,
298
+ redirects : & HashMap < String , String > ,
299
299
) -> CowStr < ' a > {
300
300
// This is a terrible hack, but should be reasonably reliable. Nobody
301
301
// should ever parse a tag with a regex. However, there isn't anything
@@ -319,7 +319,7 @@ fn adjust_links<'a>(
319
319
320
320
A_LINK
321
321
. replace_all ( & temp_html, |caps : & regex:: Captures < ' _ > | {
322
- let fixed = fix_a_links ( caps[ 2 ] . into ( ) , path, redirects. clone ( ) ) ;
322
+ let fixed = fix_a_links ( caps[ 2 ] . into ( ) , path, & redirects) ;
323
323
format ! ( "{}{}\" " , & caps[ 1 ] , fixed)
324
324
} )
325
325
. into_owned ( )
@@ -342,7 +342,12 @@ fn adjust_links<'a>(
342
342
343
343
/// Wrapper around the pulldown-cmark parser for rendering markdown to HTML.
344
344
pub fn render_markdown ( text : & str , curly_quotes : bool ) -> String {
345
- render_markdown_with_path ( text, curly_quotes, None , HashMap :: new ( ) )
345
+ render_markdown_with_path ( text, curly_quotes, None )
346
+ }
347
+
348
+ /// Wrapper around for API compatibility.
349
+ pub fn render_markdown_with_path ( text : & str , curly_quotes : bool , path : Option < & Path > ) -> String {
350
+ render_markdown_with_path_and_redirects ( text, curly_quotes, path, & HashMap :: new ( ) )
346
351
}
347
352
348
353
pub fn new_cmark_parser ( text : & str , curly_quotes : bool ) -> Parser < ' _ , ' _ > {
@@ -357,17 +362,17 @@ pub fn new_cmark_parser(text: &str, curly_quotes: bool) -> Parser<'_, '_> {
357
362
Parser :: new_ext ( text, opts)
358
363
}
359
364
360
- pub fn render_markdown_with_path (
365
+ pub fn render_markdown_with_path_and_redirects (
361
366
text : & str ,
362
367
curly_quotes : bool ,
363
368
path : Option < & Path > ,
364
- redirects : HashMap < String , String > ,
369
+ redirects : & HashMap < String , String > ,
365
370
) -> String {
366
371
let mut s = String :: with_capacity ( text. len ( ) * 3 / 2 ) ;
367
372
let p = new_cmark_parser ( text, curly_quotes) ;
368
373
let events = p
369
374
. map ( clean_codeblock_headers)
370
- . map ( |event| adjust_links ( event, path, redirects. clone ( ) ) )
375
+ . map ( |event| adjust_links ( event, path, & redirects) )
371
376
. flat_map ( |event| {
372
377
let ( a, b) = wrap_tables ( event) ;
373
378
a. into_iter ( ) . chain ( b)
0 commit comments