@@ -1051,7 +1051,11 @@ impl MarkdownSummaryLine<'_> {
1051
1051
///
1052
1052
/// Returns a tuple of the rendered HTML string and whether the output was shortened
1053
1053
/// 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 ) {
1055
1059
if md. is_empty ( ) {
1056
1060
return ( String :: new ( ) , false ) ;
1057
1061
}
@@ -1065,7 +1069,20 @@ fn markdown_summary_with_limit(md: &str, length_limit: usize) -> (String, bool)
1065
1069
* text_length += text. len ( ) ;
1066
1070
}
1067
1071
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 {
1069
1086
match & event {
1070
1087
Event :: Text ( text) => {
1071
1088
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)
1121
1138
/// Will shorten to 59 or 60 characters, including an ellipsis (…) if it was shortened.
1122
1139
///
1123
1140
/// 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 ) ;
1126
1143
1127
1144
if was_shortened {
1128
1145
s. push ( '…' ) ;
0 commit comments