@@ -732,7 +732,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
732
732
ty : item. type_ ( ) ,
733
733
name : item. name . clone ( ) . unwrap ( ) ,
734
734
path : fqp[ ..fqp. len ( ) - 1 ] . join ( "::" ) ,
735
- desc : plain_summary_line_short ( item. doc_value ( ) ) ,
735
+ desc : shorten ( plain_summary_line ( item. doc_value ( ) ) ) ,
736
736
parent : Some ( did) ,
737
737
parent_idx : None ,
738
738
search_type : get_index_search_type ( & item) ,
@@ -770,7 +770,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
770
770
}
771
771
772
772
let crate_doc = krate. module . as_ref ( ) . map ( |module| {
773
- plain_summary_line_short ( module. doc_value ( ) )
773
+ shorten ( plain_summary_line ( module. doc_value ( ) ) )
774
774
} ) . unwrap_or ( String :: new ( ) ) ;
775
775
776
776
let mut crate_data = BTreeMap :: new ( ) ;
@@ -1482,7 +1482,7 @@ impl DocFolder for Cache {
1482
1482
ty : item. type_ ( ) ,
1483
1483
name : s. to_string ( ) ,
1484
1484
path : path. join ( "::" ) ,
1485
- desc : plain_summary_line_short ( item. doc_value ( ) ) ,
1485
+ desc : shorten ( plain_summary_line ( item. doc_value ( ) ) ) ,
1486
1486
parent,
1487
1487
parent_idx : None ,
1488
1488
search_type : get_index_search_type ( & item) ,
@@ -1664,7 +1664,7 @@ impl Cache {
1664
1664
ty : item. type_ ( ) ,
1665
1665
name : item_name. to_string ( ) ,
1666
1666
path : path. clone ( ) ,
1667
- desc : plain_summary_line_short ( item. doc_value ( ) ) ,
1667
+ desc : shorten ( plain_summary_line ( item. doc_value ( ) ) ) ,
1668
1668
parent : None ,
1669
1669
parent_idx : None ,
1670
1670
search_type : get_index_search_type ( & item) ,
@@ -2360,29 +2360,39 @@ fn full_path(cx: &Context, item: &clean::Item) -> String {
2360
2360
s
2361
2361
}
2362
2362
2363
- fn shorter ( s : Option < & str > ) -> String {
2364
- match s {
2365
- Some ( s) => s. lines ( )
2366
- . skip_while ( |s| s. chars ( ) . all ( |c| c. is_whitespace ( ) ) )
2367
- . take_while ( |line|{
2368
- ( * line) . chars ( ) . any ( |chr|{
2369
- !chr. is_whitespace ( )
2370
- } )
2371
- } ) . collect :: < Vec < _ > > ( ) . join ( "\n " ) ,
2372
- None => String :: new ( )
2373
- }
2374
- }
2375
-
2376
2363
#[ inline]
2377
2364
fn plain_summary_line ( s : Option < & str > ) -> String {
2378
- let line = shorter ( s) . replace ( "\n " , " " ) ;
2379
- markdown:: plain_summary_line_full ( & line[ ..] , false )
2380
- }
2381
-
2382
- #[ inline]
2383
- fn plain_summary_line_short ( s : Option < & str > ) -> String {
2384
- let line = shorter ( s) . replace ( "\n " , " " ) ;
2385
- markdown:: plain_summary_line_full ( & line[ ..] , true )
2365
+ let s = s. unwrap_or ( "" ) ;
2366
+ // This essentially gets the first paragraph of text in one line.
2367
+ let mut line = s. lines ( )
2368
+ . skip_while ( |line| line. chars ( ) . all ( |c| c. is_whitespace ( ) ) )
2369
+ . take_while ( |line| line. chars ( ) . any ( |c| !c. is_whitespace ( ) ) )
2370
+ . fold ( String :: new ( ) , |mut acc, line| {
2371
+ acc. push_str ( line) ;
2372
+ acc. push ( ' ' ) ;
2373
+ acc
2374
+ } ) ;
2375
+ // remove final whitespace
2376
+ line. pop ( ) ;
2377
+ markdown:: plain_summary_line ( & line[ ..] )
2378
+ }
2379
+
2380
+ fn shorten ( s : String ) -> String {
2381
+ if s. chars ( ) . count ( ) > 60 {
2382
+ let mut len = 0 ;
2383
+ let mut ret = s. split_whitespace ( )
2384
+ . take_while ( |p| {
2385
+ // + 1 for the added character after the word.
2386
+ len += p. chars ( ) . count ( ) + 1 ;
2387
+ len < 60
2388
+ } )
2389
+ . collect :: < Vec < _ > > ( )
2390
+ . join ( " " ) ;
2391
+ ret. push ( '…' ) ;
2392
+ ret
2393
+ } else {
2394
+ s
2395
+ }
2386
2396
}
2387
2397
2388
2398
fn document ( w : & mut fmt:: Formatter < ' _ > , cx : & Context , item : & clean:: Item ) -> fmt:: Result {
0 commit comments