From 77667f4844e3913f20f6af4cba99f7c3b2d73310 Mon Sep 17 00:00:00 2001 From: Xipeng Jin <56369076+xipeng-jin@users.noreply.github.com> Date: Sat, 8 Nov 2025 08:00:53 -0500 Subject: [PATCH] Remove Markdown CodeBlock metadata and Custom rendering (#42211) Follow up #40736 Clean up `CodeBlockRenderer::Custom` related rendering per the previous PR [comment](https://github.com/zed-industries/zed/pull/40736#issuecomment-3503074893). Additional note here: 1. The `Custom` variant in the enum `CodeBlockRenderer` will become not useful since cleaning all code related to the custom rendering logic. 2. Need to further review the usage of code block `metadata` field in `MarkdownTag::CodeBlock` enum. I would like to have the team further review my note above so that we can make sure it will be safe to clean it up and will not affect any potential future features will be built on top of it. Thank you! Release Notes: - N/A --- crates/markdown/src/markdown.rs | 82 +-------------------------------- 1 file changed, 2 insertions(+), 80 deletions(-) diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs index 2efae05285f77b6c7ec62a6aabbab979558b0ab3..b74416d8483c6b3fbdcc4f89e7bff348b81be272 100644 --- a/crates/markdown/src/markdown.rs +++ b/crates/markdown/src/markdown.rs @@ -787,7 +787,6 @@ impl Element for MarkdownElement { }; let mut code_block_ids = HashSet::default(); - let mut current_code_block_metadata = None; let mut current_img_block_range: Option> = None; for (range, event) in parsed_markdown.events.iter() { // Skip alt text for images that rendered @@ -849,7 +848,7 @@ impl Element for MarkdownElement { markdown_end, ); } - MarkdownTag::CodeBlock { kind, metadata } => { + MarkdownTag::CodeBlock { kind, .. } => { let language = match kind { CodeBlockKind::Fenced => None, CodeBlockKind::FencedLang(language) => { @@ -862,8 +861,6 @@ impl Element for MarkdownElement { _ => None, }; - current_code_block_metadata = Some(metadata.clone()); - let is_indented = matches!(kind, CodeBlockKind::Indented); let scroll_handle = if self.style.code_block_overflow_x_scroll { code_block_ids.insert(range.start); @@ -935,64 +932,7 @@ impl Element for MarkdownElement { builder.push_code_block(language); builder.push_div(code_block, range, markdown_end); } - (CodeBlockRenderer::Custom { render, .. }, _) => { - let parent_container = render( - kind, - &parsed_markdown, - range.clone(), - metadata.clone(), - window, - cx, - ); - - let mut parent_container: AnyDiv = if let Some(scroll_handle) = - scroll_handle.as_ref() - { - let scrollbars = Scrollbars::new(ScrollAxes::Horizontal) - .id(("markdown-code-block-scrollbar", range.start)) - .tracked_scroll_handle(scroll_handle.clone()) - .with_track_along( - ScrollAxes::Horizontal, - cx.theme().colors().editor_background, - ) - .notify_content(); - - parent_container - .rounded_b_lg() - .custom_scrollbars(scrollbars, window, cx) - .into() - } else { - parent_container.into() - }; - - parent_container.style().refine(&self.style.code_block); - builder.push_div(parent_container, range, markdown_end); - - let code_block = div() - .id(("code-block", range.start)) - .rounded_b_lg() - .map(|mut code_block| { - if let Some(scroll_handle) = scroll_handle.as_ref() { - code_block.style().restrict_scroll_to_axis = - Some(true); - code_block - .flex() - .overflow_x_scroll() - .overflow_y_hidden() - .track_scroll(scroll_handle) - } else { - code_block.w_full().overflow_hidden() - } - }); - - if let Some(code_block_text_style) = &self.style.code_block.text - { - builder.push_text_style(code_block_text_style.to_owned()); - } - - builder.push_code_block(language); - builder.push_div(code_block, range, markdown_end); - } + (CodeBlockRenderer::Custom { .. }, _) => {} } } MarkdownTag::HtmlBlock => builder.push_div(div(), range, markdown_end), @@ -1131,24 +1071,6 @@ impl Element for MarkdownElement { builder.pop_text_style(); } - let metadata = current_code_block_metadata.take(); - - if let CodeBlockRenderer::Custom { - transform: Some(transform), - .. - } = &self.code_block_renderer - { - builder.modify_current_div(|el| { - transform( - el, - range.clone(), - metadata.clone().unwrap_or_default(), - window, - cx, - ) - }); - } - if let CodeBlockRenderer::Default { copy_button: true, .. } = &self.code_block_renderer