aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/markdown_remove.rs
blob: ea12cf0fc3a47592e2cac1ff853868026c55d3b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//! Removes markdown from strings.

use pulldown_cmark::{Event, Parser};

/// Removes all markdown, keeping the text and code blocks
///
/// Currently limited in styling, i.e. no ascii tables or lists
pub fn remove_markdown(markdown: &str) -> String {
    let mut out = String::new();
    let parser = Parser::new(markdown);

    for event in parser {
        match event {
            Event::Text(text) | Event::Code(text) => out.push_str(&text),
            Event::SoftBreak | Event::HardBreak | Event::Rule => out.push('\n'),
            _ => {}
        }
    }

    out
}