2020-07-08 15:37:35 -05:00
|
|
|
//! Markdown formatting.
|
|
|
|
//!
|
|
|
|
//! Sometimes, we want to display a "rich text" in the UI. At the moment, we use
|
|
|
|
//! markdown for this purpose. It doesn't feel like a right option, but that's
|
|
|
|
//! what is used by LSP, so let's keep it simple.
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
#[derive(Default, Debug)]
|
|
|
|
pub struct Markup {
|
|
|
|
text: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Markup> for String {
|
|
|
|
fn from(markup: Markup) -> Self {
|
|
|
|
markup.text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 03:03:28 -05:00
|
|
|
impl From<String> for Markup {
|
|
|
|
fn from(text: String) -> Self {
|
|
|
|
Markup { text }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 15:37:35 -05:00
|
|
|
impl fmt::Display for Markup {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fmt::Display::fmt(&self.text, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Markup {
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
self.text.as_str()
|
|
|
|
}
|
2023-03-03 09:24:08 -06:00
|
|
|
pub fn fenced_block(contents: impl fmt::Display) -> Markup {
|
2022-12-23 12:42:58 -06:00
|
|
|
format!("```rust\n{contents}\n```").into()
|
2020-07-09 03:19:37 -05:00
|
|
|
}
|
2024-01-16 07:28:47 -06:00
|
|
|
pub fn fenced_block_text(contents: impl fmt::Display) -> Markup {
|
|
|
|
format!("```text\n{contents}\n```").into()
|
|
|
|
}
|
2020-07-08 15:37:35 -05:00
|
|
|
}
|