mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-27 10:59:53 +00:00
Add inline code blocks in markdown preview (#7277)
Fixes #7236. The reason why the code was not displayed correctly is due to missing background color for the inline code block. Previously to this PR: <img width="1840" alt="SCR-20240202-mclv" src="https://github.com/zed-industries/zed/assets/67913738/92f63e72-db86-4de9-bb42-40549679e159" alt="Screenshot showing that inline code blocks are not highlighted in Markdown preview"> After this PR: <img width="1796" alt="SCR-20240202-mccs" src="https://github.com/zed-industries/zed/assets/67913738/5cf039af-82d7-41b8-b461-f79dec5ddf6a" alt="Screenshot showing that inline code blocks are now highlighted in Markdown preview"> Release Notes: - Fixed inline code block not shown in markdown preview ([#7236](https://github.com/zed-industries/zed/issues/7236)).
This commit is contained in:
parent
79c1003b34
commit
980d4f1003
1 changed files with 22 additions and 12 deletions
|
@ -13,6 +13,7 @@ use util::RangeExt;
|
|||
pub enum Highlight {
|
||||
Code,
|
||||
Id(HighlightId),
|
||||
InlineCode(bool),
|
||||
Highlight(HighlightStyle),
|
||||
Mention,
|
||||
SelfMention,
|
||||
|
@ -67,6 +68,23 @@ impl RichText {
|
|||
background_color: Some(code_background),
|
||||
..id.style(theme.syntax()).unwrap_or_default()
|
||||
},
|
||||
Highlight::InlineCode(link) => {
|
||||
if !*link {
|
||||
HighlightStyle {
|
||||
background_color: Some(code_background),
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
HighlightStyle {
|
||||
background_color: Some(code_background),
|
||||
underline: Some(UnderlineStyle {
|
||||
thickness: 1.0.into(),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
Highlight::Highlight(highlight) => *highlight,
|
||||
Highlight::Mention => HighlightStyle {
|
||||
font_weight: Some(FontWeight::BOLD),
|
||||
|
@ -184,22 +202,14 @@ pub fn render_markdown_mut(
|
|||
}
|
||||
Event::Code(t) => {
|
||||
text.push_str(t.as_ref());
|
||||
if link_url.is_some() {
|
||||
highlights.push((
|
||||
prev_len..text.len(),
|
||||
Highlight::Highlight(HighlightStyle {
|
||||
underline: Some(UnderlineStyle {
|
||||
thickness: 1.0.into(),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
));
|
||||
}
|
||||
let is_link = link_url.is_some();
|
||||
|
||||
if let Some(link_url) = link_url.clone() {
|
||||
link_ranges.push(prev_len..text.len());
|
||||
link_urls.push(link_url);
|
||||
}
|
||||
|
||||
highlights.push((prev_len..text.len(), Highlight::InlineCode(is_link)))
|
||||
}
|
||||
Event::Start(tag) => match tag {
|
||||
Tag::Paragraph => new_paragraph(text, &mut list_stack),
|
||||
|
|
Loading…
Reference in a new issue