Detailed changes
@@ -1,5 +1,5 @@
use gpui::{
- DefiniteLength, FontStyle, FontWeight, HighlightStyle, SharedString, StrikethroughStyle,
+ DefiniteLength, FontStyle, FontWeight, HighlightStyle, Hsla, SharedString, StrikethroughStyle,
UnderlineStyle, px,
};
use language::HighlightId;
@@ -175,7 +175,11 @@ pub enum MarkdownHighlight {
impl MarkdownHighlight {
/// Converts this [`MarkdownHighlight`] to a [`HighlightStyle`].
- pub fn to_highlight_style(&self, theme: &theme::SyntaxTheme) -> Option<HighlightStyle> {
+ pub fn to_highlight_style(
+ &self,
+ theme: &theme::SyntaxTheme,
+ link_color: Hsla,
+ ) -> Option<HighlightStyle> {
match self {
MarkdownHighlight::Style(style) => {
let mut highlight = HighlightStyle::default();
@@ -202,6 +206,15 @@ impl MarkdownHighlight {
highlight.font_weight = Some(style.weight);
}
+ if style.link {
+ highlight.underline = Some(UnderlineStyle {
+ thickness: px(1.),
+ color: Some(link_color),
+ ..Default::default()
+ });
+ highlight.color = Some(link_color);
+ }
+
Some(highlight)
}
@@ -221,6 +234,8 @@ pub struct MarkdownHighlightStyle {
pub strikethrough: bool,
/// The weight of the text.
pub weight: FontWeight,
+ /// Whether the text should be stylized as link.
+ pub link: bool,
}
/// A parsed region in a Markdown document.
@@ -261,7 +261,7 @@ impl<'a> MarkdownParser<'a> {
code: false,
link: Some(link),
});
- style.underline = true;
+ style.link = true;
prev_len
} else {
// Manually scan for links
@@ -329,7 +329,7 @@ impl<'a> MarkdownParser<'a> {
highlights.push((
prev_len..text.len(),
MarkdownHighlight::Style(MarkdownHighlightStyle {
- underline: true,
+ link: true,
..Default::default()
}),
));
@@ -53,6 +53,7 @@ pub struct RenderContext {
border_color: Hsla,
element_background_color: Hsla,
text_color: Hsla,
+ link_color: Hsla,
window_rem_size: Pixels,
text_muted_color: Hsla,
code_block_background_color: Hsla,
@@ -87,6 +88,7 @@ impl RenderContext {
border_color: theme.colors().border,
element_background_color: theme.colors().element_background,
text_color: theme.colors().text,
+ link_color: theme.colors().text_accent,
window_rem_size: window.rem_size(),
text_muted_color: theme.colors().text_muted,
code_block_background_color: theme.colors().surface_background,
@@ -656,6 +658,7 @@ fn render_markdown_text(parsed_new: &MarkdownParagraph, cx: &mut RenderContext)
let workspace_clone = cx.workspace.clone();
let code_span_bg_color = cx.code_span_background_color;
let text_style = cx.text_style.clone();
+ let link_color = cx.link_color;
for parsed_region in parsed_new {
match parsed_region {
@@ -665,7 +668,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)
+ .to_highlight_style(&syntax_theme, link_color)
.map(|style| (range.clone(), style))
}),
parsed.regions.iter().zip(&parsed.region_ranges).filter_map(