@@ -1051,7 +1051,11 @@ impl MarkdownSummaryLine<'_> {
10511051///
10521052/// Returns a tuple of the rendered HTML string and whether the output was shortened
10531053/// due to the provided `length_limit`.
1054- fn markdown_summary_with_limit ( md : & str , length_limit : usize ) -> ( String , bool ) {
1054+ fn markdown_summary_with_limit (
1055+ md : & str ,
1056+ link_names : & [ RenderedLink ] ,
1057+ length_limit : usize ,
1058+ ) -> ( String , bool ) {
10551059 if md. is_empty ( ) {
10561060 return ( String :: new ( ) , false ) ;
10571061 }
@@ -1065,7 +1069,20 @@ fn markdown_summary_with_limit(md: &str, length_limit: usize) -> (String, bool)
10651069 * text_length += text. len ( ) ;
10661070 }
10671071
1068- ' outer: for event in Parser :: new_ext ( md, summary_opts ( ) ) {
1072+ let mut replacer = |broken_link : BrokenLink < ' _ > | {
1073+ if let Some ( link) =
1074+ link_names. iter ( ) . find ( |link| & * link. original_text == broken_link. reference )
1075+ {
1076+ Some ( ( link. href . as_str ( ) . into ( ) , link. new_text . as_str ( ) . into ( ) ) )
1077+ } else {
1078+ None
1079+ }
1080+ } ;
1081+
1082+ let p = Parser :: new_with_broken_link_callback ( md, opts ( ) , Some ( & mut replacer) ) ;
1083+ let p = LinkReplacer :: new ( p, link_names) ;
1084+
1085+ ' outer: for event in p {
10691086 match & event {
10701087 Event :: Text ( text) => {
10711088 for word in text. split_inclusive ( char:: is_whitespace) {
@@ -1121,8 +1138,8 @@ fn markdown_summary_with_limit(md: &str, length_limit: usize) -> (String, bool)
11211138/// Will shorten to 59 or 60 characters, including an ellipsis (…) if it was shortened.
11221139///
11231140/// See [`markdown_summary_with_limit`] for details about what is rendered and what is not.
1124- crate fn short_markdown_summary ( markdown : & str ) -> String {
1125- let ( mut s, was_shortened) = markdown_summary_with_limit ( markdown, 59 ) ;
1141+ crate fn short_markdown_summary ( markdown : & str , link_names : & [ RenderedLink ] ) -> String {
1142+ let ( mut s, was_shortened) = markdown_summary_with_limit ( markdown, link_names , 59 ) ;
11261143
11271144 if was_shortened {
11281145 s. push ( '…' ) ;
0 commit comments