Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

markdown: Apply heading level text styles to the shaped text (#63465)

Daniel Shneyder6c3656986775
diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs
index 53c1aadd884..95e17cf30ce 100644
--- a/crates/markdown/src/markdown.rs
+++ b/crates/markdown/src/markdown.rs
@@ -1938,9 +1938,15 @@ impl MarkdownElement {
};
let mut heading_style = self.style.heading.clone();
- let heading_text_style = heading_style.text_style().clone();
+ let mut heading_text_style = heading_style.text_style().clone();
heading.style().refine(&heading_style);
+ if let Some(level_style) =
+ heading_level_style(level, self.style.heading_level_styles.as_ref())
+ {
+ heading_text_style.refine(level_style);
+ }
+
builder.push_text_style(TextStyleRefinement {
text_align: Some(align),
..heading_text_style
@@ -3341,24 +3347,28 @@ fn apply_heading_style(
};
}
- if let Some(styles) = custom_styles {
- let style_opt = match level {
- pulldown_cmark::HeadingLevel::H1 => &styles.h1,
- pulldown_cmark::HeadingLevel::H2 => &styles.h2,
- pulldown_cmark::HeadingLevel::H3 => &styles.h3,
- pulldown_cmark::HeadingLevel::H4 => &styles.h4,
- pulldown_cmark::HeadingLevel::H5 => &styles.h5,
- pulldown_cmark::HeadingLevel::H6 => &styles.h6,
- };
-
- if let Some(style) = style_opt {
- heading.style().text = style.clone();
- }
+ if let Some(style) = heading_level_style(level, custom_styles) {
+ heading.style().text = style.clone();
}
heading
}
+fn heading_level_style(
+ level: pulldown_cmark::HeadingLevel,
+ custom_styles: Option<&HeadingLevelStyles>,
+) -> Option<&TextStyleRefinement> {
+ let styles = custom_styles?;
+ match level {
+ pulldown_cmark::HeadingLevel::H1 => styles.h1.as_ref(),
+ pulldown_cmark::HeadingLevel::H2 => styles.h2.as_ref(),
+ pulldown_cmark::HeadingLevel::H3 => styles.h3.as_ref(),
+ pulldown_cmark::HeadingLevel::H4 => styles.h4.as_ref(),
+ pulldown_cmark::HeadingLevel::H5 => styles.h5.as_ref(),
+ pulldown_cmark::HeadingLevel::H6 => styles.h6.as_ref(),
+ }
+}
+
fn render_wrap_code_block_button(
id: usize,
is_wrapped: bool,