From c6f776c5f9aa7d850be24d0288700905e833dc9e Mon Sep 17 00:00:00 2001 From: Raymond Luo Date: Mon, 20 Jun 2022 21:10:45 -0400 Subject: [PATCH] determine doc link type from start instead of text or code --- crates/ide/src/doc_links.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 08085ac7841..a78358f20fd 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -362,14 +362,15 @@ fn map_links<'e>( // holds the origin link target on start event and the rewritten one on end event let mut end_link_target: Option = None; // normally link's type is determined by the type of link tag in the end event, - // however in same cases we want to change the link type, for example, + // however in some cases we want to change the link type, for example, // `Shortcut` type doesn't make sense for url links let mut end_link_type: Option = None; events.map(move |evt| match evt { - Event::Start(Tag::Link(_, ref target, _)) => { + Event::Start(Tag::Link(link_type, ref target, _)) => { in_link = true; end_link_target = Some(target.clone()); + end_link_type = Some(link_type); evt } Event::End(Tag::Link(link_type, target, _)) => { @@ -381,17 +382,13 @@ fn map_links<'e>( )) } Event::Text(s) if in_link => { - let (link_type, link_target_s, link_name) = - callback(&end_link_target.take().unwrap(), &s); + let (_, link_target_s, link_name) = callback(&end_link_target.take().unwrap(), &s); end_link_target = Some(CowStr::Boxed(link_target_s.into())); - end_link_type = link_type; Event::Text(CowStr::Boxed(link_name.into())) } Event::Code(s) if in_link => { - let (link_type, link_target_s, link_name) = - callback(&end_link_target.take().unwrap(), &s); + let (_, link_target_s, link_name) = callback(&end_link_target.take().unwrap(), &s); end_link_target = Some(CowStr::Boxed(link_target_s.into())); - end_link_type = link_type; Event::Code(CowStr::Boxed(link_name.into())) } _ => evt,