]> git.lizzy.rs Git - rust.git/blob - src/tools/rust-analyzer/crates/ide/src/markdown_remove.rs
Rollup merge of #100228 - luqmana:suggestion-ice, r=estebank
[rust.git] / src / tools / rust-analyzer / crates / ide / src / markdown_remove.rs
1 //! Removes markdown from strings.
2 use pulldown_cmark::{Event, Parser, Tag};
3
4 /// Removes all markdown, keeping the text and code blocks
5 ///
6 /// Currently limited in styling, i.e. no ascii tables or lists
7 pub(crate) fn remove_markdown(markdown: &str) -> String {
8     let mut out = String::new();
9     let parser = Parser::new(markdown);
10
11     for event in parser {
12         match event {
13             Event::Text(text) | Event::Code(text) => out.push_str(&text),
14             Event::SoftBreak | Event::HardBreak | Event::Rule | Event::End(Tag::CodeBlock(_)) => {
15                 out.push('\n')
16             }
17             _ => {}
18         }
19     }
20
21     out
22 }