From 287314f415742c6861dfff5425072e34e7a578a7 Mon Sep 17 00:00:00 2001 From: Bartosz Kaszubowski Date: Sat, 18 Oct 2025 00:43:44 +0200 Subject: [PATCH] markdown_preview: Improve the link decoration logic (#39905) Closes #39838 Refs: * https://github.com/zed-industries/zed/pull/39149#issuecomment-3383015060 # How After digging a bit more to find out why raw links are not colored in Markdown renderer I have found a simpler approach to applying color decoration, which also fixed the lack of colors on raw links mentioned in issue and comment above. Release Notes: - Improved decoration logic for links in Markdown # Preview Screenshot 2025-10-09 at 23 39 09 --- crates/markdown_preview/src/markdown_elements.rs | 10 ++-------- crates/markdown_preview/src/markdown_renderer.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/markdown_preview/src/markdown_elements.rs b/crates/markdown_preview/src/markdown_elements.rs index 827c11f0453817b00431a1f32db8c645aced4e86..d0bde48889143b8ab9f66d9dc2839ebabf7d3541 100644 --- a/crates/markdown_preview/src/markdown_elements.rs +++ b/crates/markdown_preview/src/markdown_elements.rs @@ -1,5 +1,5 @@ use gpui::{ - DefiniteLength, FontStyle, FontWeight, HighlightStyle, Hsla, SharedString, StrikethroughStyle, + DefiniteLength, FontStyle, FontWeight, HighlightStyle, SharedString, StrikethroughStyle, UnderlineStyle, px, }; use language::HighlightId; @@ -175,11 +175,7 @@ pub enum MarkdownHighlight { impl MarkdownHighlight { /// Converts this [`MarkdownHighlight`] to a [`HighlightStyle`]. - pub fn to_highlight_style( - &self, - theme: &theme::SyntaxTheme, - link_color: Hsla, - ) -> Option { + pub fn to_highlight_style(&self, theme: &theme::SyntaxTheme) -> Option { match self { MarkdownHighlight::Style(style) => { let mut highlight = HighlightStyle::default(); @@ -209,10 +205,8 @@ impl MarkdownHighlight { if style.link { highlight.underline = Some(UnderlineStyle { thickness: px(1.), - color: Some(link_color), ..Default::default() }); - highlight.color = Some(link_color); } Some(highlight) diff --git a/crates/markdown_preview/src/markdown_renderer.rs b/crates/markdown_preview/src/markdown_renderer.rs index 489ce532f0060d29436d008413be1391044ab3e3..6f794b1358a1869779b01f6af3069bf8be735e7e 100644 --- a/crates/markdown_preview/src/markdown_renderer.rs +++ b/crates/markdown_preview/src/markdown_renderer.rs @@ -692,7 +692,7 @@ fn render_markdown_text(parsed_new: &MarkdownParagraph, cx: &mut RenderContext) let highlights = gpui::combine_highlights( parsed.highlights.iter().filter_map(|(range, highlight)| { highlight - .to_highlight_style(&syntax_theme, link_color) + .to_highlight_style(&syntax_theme) .map(|style| (range.clone(), style)) }), parsed.regions.iter().zip(&parsed.region_ranges).filter_map( @@ -705,6 +705,14 @@ fn render_markdown_text(parsed_new: &MarkdownParagraph, cx: &mut RenderContext) ..Default::default() }, )) + } else if region.link.is_some() { + Some(( + range.clone(), + HighlightStyle { + color: Some(link_color), + ..Default::default() + }, + )) } else { None }