@@ -85,34 +85,28 @@ static URL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
8585
8686fn find_raw_urls (
8787 cx : & DocContext < ' _ > ,
88- whole_text : & str ,
88+ dox : & str ,
8989 text : & str ,
9090 range : Range < usize > ,
9191 f : & impl Fn ( & DocContext < ' _ > , & ' static str , Range < usize > , Option < & str > ) ,
9292) {
9393 trace ! ( "looking for raw urls in {text}" ) ;
9494 // For now, we only check "full" URLs (meaning, starting with "http://" or "https://").
9595 for match_ in URL_REGEX . find_iter ( text) {
96- let url_range = match_. range ( ) ;
96+ let mut url_range = match_. range ( ) ;
97+ url_range. start += range. start ;
98+ url_range. end += range. start ;
9799 let mut without_brackets = None ;
98- let mut extra_range = 0 ;
99- // If the whole text is contained inside `[]`, then we need to replace the brackets and
100+ // If the link is contained inside `[]`, then we need to replace the brackets and
100101 // not just add `<>`.
101- if whole_text [ ..range . start + url_range. start ] . ends_with ( '[' )
102- && range . start + url_range. end <= whole_text . len ( )
103- && whole_text [ range . start + url_range. end ..] . starts_with ( ']' )
102+ if dox [ ..url_range. start ] . ends_with ( '[' )
103+ && url_range. end <= dox . len ( )
104+ && dox [ url_range. end ..] . starts_with ( ']' )
104105 {
105- extra_range = 1 ;
106+ url_range. start -= 1 ;
107+ url_range. end += 1 ;
106108 without_brackets = Some ( match_. as_str ( ) ) ;
107109 }
108- f (
109- cx,
110- "this URL is not a hyperlink" ,
111- Range {
112- start : range. start + url_range. start - extra_range,
113- end : range. start + url_range. end + extra_range,
114- } ,
115- without_brackets,
116- ) ;
110+ f ( cx, "this URL is not a hyperlink" , url_range, without_brackets) ;
117111 }
118112}
0 commit comments