@@ -146,7 +146,7 @@ pub fn normalize_path_id(mut path: String) -> String {
146146fn adjust_links < ' a > (
147147 event : Event < ' a > ,
148148 path : Option < & Path > ,
149- redirects : HashMap < String , String > ,
149+ redirects : & HashMap < String , String > ,
150150) -> Event < ' a > {
151151 static SCHEME_LINK : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"^[a-z][a-z0-9+.-]*:" ) . unwrap ( ) ) ;
152152 static HTML_MD_LINK : Lazy < Regex > =
@@ -176,14 +176,14 @@ fn adjust_links<'a>(
176176 fn fix_a_links < ' a > (
177177 dest : CowStr < ' a > ,
178178 path : Option < & Path > ,
179- redirects : HashMap < String , String > ,
179+ redirects : & HashMap < String , String > ,
180180 ) -> CowStr < ' a > {
181181 if dest. starts_with ( '#' ) {
182182 // Fragment-only link.
183183 if let Some ( path) = path {
184184 let mut base = path. display ( ) . to_string ( ) ;
185185 if base. ends_with ( ".md" ) {
186- base. replace_range ( base. len ( ) - 3 .. , "" ) ;
186+ base. truncate ( base. len ( ) - 3 ) ;
187187 }
188188 return format ! (
189189 "#{}{}" ,
@@ -228,7 +228,7 @@ fn adjust_links<'a>(
228228 if let Some ( _) = path {
229229 // Fix redirect links
230230 let normalized_path_split: Vec < & str > = normalized_path. split ( '#' ) . collect ( ) ;
231- for ( original, redirect) in & redirects {
231+ for ( original, redirect) in redirects {
232232 if normalize_path ( original. trim_start_matches ( '/' ) )
233233 . eq_ignore_ascii_case ( & normalized_path)
234234 || normalize_path ( original. trim_start_matches ( '/' ) )
@@ -295,7 +295,7 @@ fn adjust_links<'a>(
295295 fn fix_html < ' a > (
296296 html : CowStr < ' a > ,
297297 path : Option < & Path > ,
298- redirects : HashMap < String , String > ,
298+ redirects : & HashMap < String , String > ,
299299 ) -> CowStr < ' a > {
300300 // This is a terrible hack, but should be reasonably reliable. Nobody
301301 // should ever parse a tag with a regex. However, there isn't anything
@@ -319,7 +319,7 @@ fn adjust_links<'a>(
319319
320320 A_LINK
321321 . 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) ;
323323 format ! ( "{}{}\" " , & caps[ 1 ] , fixed)
324324 } )
325325 . into_owned ( )
@@ -342,7 +342,12 @@ fn adjust_links<'a>(
342342
343343/// Wrapper around the pulldown-cmark parser for rendering markdown to HTML.
344344pub 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 ( ) )
346351}
347352
348353pub 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<'_, '_> {
357362 Parser :: new_ext ( text, opts)
358363}
359364
360- pub fn render_markdown_with_path (
365+ pub fn render_markdown_with_path_and_redirects (
361366 text : & str ,
362367 curly_quotes : bool ,
363368 path : Option < & Path > ,
364- redirects : HashMap < String , String > ,
369+ redirects : & HashMap < String , String > ,
365370) -> String {
366371 let mut s = String :: with_capacity ( text. len ( ) * 3 / 2 ) ;
367372 let p = new_cmark_parser ( text, curly_quotes) ;
368373 let events = p
369374 . map ( clean_codeblock_headers)
370- . map ( |event| adjust_links ( event, path, redirects. clone ( ) ) )
375+ . map ( |event| adjust_links ( event, path, & redirects) )
371376 . flat_map ( |event| {
372377 let ( a, b) = wrap_tables ( event) ;
373378 a. into_iter ( ) . chain ( b)
0 commit comments