markdown preview: highlight code blocks (#9087)
 Release Notes: - Added syntax highlighting to code blocks in markdown preview - Fixed scroll position in markdown preview when editing a markdown file (#9208)
This commit is contained in:
parent
e5bd9f184b
commit
d362588055
9 changed files with 264 additions and 126 deletions
|
@ -248,11 +248,25 @@ fn render_markdown_code_block(
|
|||
parsed: &ParsedMarkdownCodeBlock,
|
||||
cx: &mut RenderContext,
|
||||
) -> AnyElement {
|
||||
let body = if let Some(highlights) = parsed.highlights.as_ref() {
|
||||
StyledText::new(parsed.contents.clone()).with_highlights(
|
||||
&cx.text_style,
|
||||
highlights.iter().filter_map(|(range, highlight_id)| {
|
||||
highlight_id
|
||||
.style(cx.syntax_theme.as_ref())
|
||||
.map(|style| (range.clone(), style))
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
StyledText::new(parsed.contents.clone())
|
||||
};
|
||||
|
||||
cx.with_common_p(div())
|
||||
.px_3()
|
||||
.py_3()
|
||||
.bg(cx.code_block_background_color)
|
||||
.child(StyledText::new(parsed.contents.clone()))
|
||||
.rounded_md()
|
||||
.child(body)
|
||||
.into_any()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue