ide/
markup.rs

1//! Markdown formatting.
2//!
3//! Sometimes, we want to display a "rich text" in the UI. At the moment, we use
4//! markdown for this purpose. It doesn't feel like a right option, but that's
5//! what is used by LSP, so let's keep it simple.
6use std::fmt;
7
8#[derive(Clone, Default, Debug, Hash, PartialEq, Eq)]
9pub struct Markup {
10    text: String,
11}
12
13impl From<Markup> for String {
14    fn from(markup: Markup) -> Self {
15        markup.text
16    }
17}
18
19impl From<String> for Markup {
20    fn from(text: String) -> Self {
21        Markup { text }
22    }
23}
24
25impl fmt::Display for Markup {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        fmt::Display::fmt(&self.text, f)
28    }
29}
30
31impl Markup {
32    pub fn as_str(&self) -> &str {
33        self.text.as_str()
34    }
35    pub fn fenced_block(contents: impl fmt::Display) -> Markup {
36        format!("```rust\n{contents}\n```").into()
37    }
38    pub fn fenced_block_text(contents: impl fmt::Display) -> Markup {
39        format!("```text\n{contents}\n```").into()
40    }
41}