Skip to content

Commit a281a2d

Browse files
SimekP1n3appl3
authored andcommitted
markdown_preview: Improve the link decoration logic (zed-industries#39905)
Closes zed-industries#39838 Refs: * zed-industries#39149 (comment) # 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 <img width="1712" height="820" alt="Screenshot 2025-10-09 at 23 39 09" src="https://github.com/user-attachments/assets/3864cb6c-3fc6-4110-8067-6158cd4b58f5" />
1 parent df6fb22 commit a281a2d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

crates/markdown_preview/src/markdown_elements.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use gpui::{
2-
DefiniteLength, FontStyle, FontWeight, HighlightStyle, Hsla, SharedString, StrikethroughStyle,
2+
DefiniteLength, FontStyle, FontWeight, HighlightStyle, SharedString, StrikethroughStyle,
33
UnderlineStyle, px,
44
};
55
use language::HighlightId;
@@ -175,11 +175,7 @@ pub enum MarkdownHighlight {
175175

176176
impl MarkdownHighlight {
177177
/// Converts this [`MarkdownHighlight`] to a [`HighlightStyle`].
178-
pub fn to_highlight_style(
179-
&self,
180-
theme: &theme::SyntaxTheme,
181-
link_color: Hsla,
182-
) -> Option<HighlightStyle> {
178+
pub fn to_highlight_style(&self, theme: &theme::SyntaxTheme) -> Option<HighlightStyle> {
183179
match self {
184180
MarkdownHighlight::Style(style) => {
185181
let mut highlight = HighlightStyle::default();
@@ -209,10 +205,8 @@ impl MarkdownHighlight {
209205
if style.link {
210206
highlight.underline = Some(UnderlineStyle {
211207
thickness: px(1.),
212-
color: Some(link_color),
213208
..Default::default()
214209
});
215-
highlight.color = Some(link_color);
216210
}
217211

218212
Some(highlight)

crates/markdown_preview/src/markdown_renderer.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ fn render_markdown_text(parsed_new: &MarkdownParagraph, cx: &mut RenderContext)
692692
let highlights = gpui::combine_highlights(
693693
parsed.highlights.iter().filter_map(|(range, highlight)| {
694694
highlight
695-
.to_highlight_style(&syntax_theme, link_color)
695+
.to_highlight_style(&syntax_theme)
696696
.map(|style| (range.clone(), style))
697697
}),
698698
parsed.regions.iter().zip(&parsed.region_ranges).filter_map(
@@ -705,6 +705,14 @@ fn render_markdown_text(parsed_new: &MarkdownParagraph, cx: &mut RenderContext)
705705
..Default::default()
706706
},
707707
))
708+
} else if region.link.is_some() {
709+
Some((
710+
range.clone(),
711+
HighlightStyle {
712+
color: Some(link_color),
713+
..Default::default()
714+
},
715+
))
708716
} else {
709717
None
710718
}

0 commit comments

Comments
 (0)