From c834ea75efdf3f9f6ffa6271d44c1d306a284a27 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Tue, 16 Apr 2024 12:40:13 +0200 Subject: [PATCH] Fix `---` in Markdown docs not rendered correctly (#10606) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes #10511 by turning off the YAML metadata block rendering in the Markdown parser. `clangd` uses `---` as dividers, but our parser interpreted it as a YAML metadata block, even though it didn't contain any valid YAML. Example Markdown from `clangd`: ### instance-method `format` --- → `void` Parameters: - `const int &` - `const std::tm &` - `int & dest` --- ```cpp // In my_formatter_flag public: void format(const int &, const std::tm &, int &dest) ``` What's between the two `---` is *not* valid YAML. Neovim, too, interprets these as dividers and renders them as such. And since we don't handle any possible metadata anyway, we can turn off the metadata handling, which causes the parser to interpret the `---` as dividers. Release Notes: - Fixed Markdown returned by `clangd` being rendered the wrong way. ([#10511](https://github.com/zed-industries/zed/issues/10511)). Before: ![screenshot-2024-04-16-12 32 15@2x](https://github.com/zed-industries/zed/assets/1185253/a268f106-9504-48aa-9744-42a7521de807) After: ![screenshot-2024-04-16-12 33 02@2x](https://github.com/zed-industries/zed/assets/1185253/dd178a63-a075-48a9-85d9-565157a5b050) Co-authored-by: Bennet --- crates/language/src/markdown.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/language/src/markdown.rs b/crates/language/src/markdown.rs index 8f027c76e346b1fe94fd2ff6ba9ac8bf2f3e8efe..2735e6f090cb1ed718a96f8c3d4be266add48c32 100644 --- a/crates/language/src/markdown.rs +++ b/crates/language/src/markdown.rs @@ -5,7 +5,7 @@ use std::{ops::Range, path::PathBuf}; use crate::{HighlightId, Language, LanguageRegistry}; use gpui::{px, FontStyle, FontWeight, HighlightStyle, StrikethroughStyle, UnderlineStyle}; -use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd}; +use pulldown_cmark::{CodeBlockKind, Event, Parser, Tag, TagEnd}; /// Parsed Markdown content. #[derive(Debug, Clone, Default)] @@ -165,7 +165,10 @@ pub async fn parse_markdown_block( let mut current_language = None; let mut list_stack = Vec::new(); - for event in Parser::new_ext(markdown, Options::all()) { + let mut options = pulldown_cmark::Options::all(); + options.remove(pulldown_cmark::Options::ENABLE_YAML_STYLE_METADATA_BLOCKS); + + for event in Parser::new_ext(markdown, options) { let prev_len = text.len(); match event { Event::Text(t) => {