@@ -1348,6 +1348,55 @@ impl<'a> Markdown<'a> {
13481348 CodeBlocks :: new ( p, codes, edition, playground)
13491349 } )
13501350 }
1351+
1352+ /// Convert markdown to (summary, remaining) HTML.
1353+ ///
1354+ /// - The summary is the first top-level Markdown element (usually a paragraph, but potentially
1355+ /// any block).
1356+ /// - The remaining docs contain everything after the summary.
1357+ pub ( crate ) fn split_summary_and_content ( self ) -> ( Option < String > , Option < String > ) {
1358+ if self . content . is_empty ( ) {
1359+ return ( None , None ) ;
1360+ }
1361+ let mut p = self . into_iter ( ) ;
1362+
1363+ let mut event_level = 0 ;
1364+ let mut summary_events = Vec :: new ( ) ;
1365+ let mut get_next_tag = false ;
1366+
1367+ let mut end_of_summary = false ;
1368+ while let Some ( event) = p. next ( ) {
1369+ match event {
1370+ Event :: Start ( _) => event_level += 1 ,
1371+ Event :: End ( kind) => {
1372+ event_level -= 1 ;
1373+ if event_level == 0 {
1374+ // We're back at the "top" so it means we're done with the summary.
1375+ end_of_summary = true ;
1376+ // We surround tables with `<div>` HTML tags so this is a special case.
1377+ get_next_tag = kind == TagEnd :: Table ;
1378+ }
1379+ }
1380+ _ => { }
1381+ }
1382+ summary_events. push ( event) ;
1383+ if end_of_summary {
1384+ if get_next_tag && let Some ( event) = p. next ( ) {
1385+ summary_events. push ( event) ;
1386+ }
1387+ break ;
1388+ }
1389+ }
1390+ let mut summary = String :: new ( ) ;
1391+ html:: push_html ( & mut summary, summary_events. into_iter ( ) ) ;
1392+ if summary. is_empty ( ) {
1393+ return ( None , None ) ;
1394+ }
1395+ let mut content = String :: new ( ) ;
1396+ html:: push_html ( & mut content, p) ;
1397+
1398+ if content. is_empty ( ) { ( Some ( summary) , None ) } else { ( Some ( summary) , Some ( content) ) }
1399+ }
13511400}
13521401
13531402impl MarkdownWithToc < ' _ > {
@@ -1421,52 +1470,6 @@ impl MarkdownItemInfo<'_> {
14211470 }
14221471}
14231472
1424- pub ( crate ) fn markdown_split_summary_and_content (
1425- md : Markdown < ' _ > ,
1426- ) -> ( Option < String > , Option < String > ) {
1427- if md. content . is_empty ( ) {
1428- return ( None , None ) ;
1429- }
1430- let mut p = md. into_iter ( ) ;
1431-
1432- let mut event_level = 0 ;
1433- let mut summary_events = Vec :: new ( ) ;
1434- let mut get_next_tag = false ;
1435-
1436- let mut end_of_summary = false ;
1437- while let Some ( event) = p. next ( ) {
1438- match event {
1439- Event :: Start ( _) => event_level += 1 ,
1440- Event :: End ( kind) => {
1441- event_level -= 1 ;
1442- if event_level == 0 {
1443- // We're back at the "top" so it means we're done with the summary.
1444- end_of_summary = true ;
1445- // We surround tables with `<div>` HTML tags so this is a special case.
1446- get_next_tag = kind == TagEnd :: Table ;
1447- }
1448- }
1449- _ => { }
1450- }
1451- summary_events. push ( event) ;
1452- if end_of_summary {
1453- if get_next_tag && let Some ( event) = p. next ( ) {
1454- summary_events. push ( event) ;
1455- }
1456- break ;
1457- }
1458- }
1459- let mut summary = String :: new ( ) ;
1460- html:: push_html ( & mut summary, summary_events. into_iter ( ) ) ;
1461- if summary. is_empty ( ) {
1462- return ( None , None ) ;
1463- }
1464- let mut content = String :: new ( ) ;
1465- html:: push_html ( & mut content, p) ;
1466-
1467- if content. is_empty ( ) { ( Some ( summary) , None ) } else { ( Some ( summary) , Some ( content) ) }
1468- }
1469-
14701473impl MarkdownSummaryLine < ' _ > {
14711474 pub ( crate ) fn into_string_with_has_more_content ( self ) -> ( String , bool ) {
14721475 let MarkdownSummaryLine ( md, links) = self ;
0 commit comments