@@ -1240,7 +1240,7 @@ pub(crate) fn plain_text_summary(md: &str, link_names: &[RenderedLink]) -> Strin
12401240pub ( crate ) struct MarkdownLink {
12411241 pub kind : LinkType ,
12421242 pub link : String ,
1243- pub display_text : String ,
1243+ pub display_text : Option < String > ,
12441244 pub range : MarkdownLinkRange ,
12451245}
12461246
@@ -1402,13 +1402,23 @@ pub(crate) fn markdown_links<'md, R>(
14021402 LinkType :: Autolink | LinkType :: Email => unreachable ! ( ) ,
14031403 } ;
14041404
1405- let display_text =
1406- collect_link_data ( & mut event_iter) . map_or ( String :: new ( ) , CowStr :: into_string) ;
1405+ let display_text = if matches ! (
1406+ link_type,
1407+ LinkType :: Inline
1408+ | LinkType :: ReferenceUnknown
1409+ | LinkType :: Reference
1410+ | LinkType :: Shortcut
1411+ | LinkType :: ShortcutUnknown
1412+ ) {
1413+ collect_link_data ( & mut event_iter)
1414+ } else {
1415+ None
1416+ } ;
14071417
14081418 if let Some ( link) = preprocess_link ( MarkdownLink {
14091419 kind : link_type,
1410- display_text,
14111420 link : dest. into_string ( ) ,
1421+ display_text,
14121422 range,
14131423 } ) {
14141424 links. push ( link) ;
@@ -1424,16 +1434,23 @@ pub(crate) fn markdown_links<'md, R>(
14241434/// Collects additional data of link.
14251435fn collect_link_data < ' input , ' callback > (
14261436 event_iter : & mut OffsetIter < ' input , ' callback > ,
1427- ) -> Option < CowStr < ' input > > {
1428- let mut display_text = None ;
1437+ ) -> Option < String > {
1438+ let mut display_text: Option < String > = None ;
1439+ let mut append_text = |text : CowStr < ' _ > | {
1440+ if let Some ( display_text) = & mut display_text {
1441+ display_text. push_str ( & text) ;
1442+ } else {
1443+ display_text = Some ( text. to_string ( ) ) ;
1444+ }
1445+ } ;
14291446
14301447 while let Some ( ( event, _span) ) = event_iter. next ( ) {
14311448 match event {
1432- Event :: Text ( code ) => {
1433- display_text = Some ( code ) ;
1449+ Event :: Text ( text ) => {
1450+ append_text ( text ) ;
14341451 }
14351452 Event :: Code ( code) => {
1436- display_text = Some ( code) ;
1453+ append_text ( code) ;
14371454 }
14381455 Event :: End ( _) => {
14391456 break ;
0 commit comments