From 1b0c7701cc97cd7bef8bb9729011d4cf291a60c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 17:42:52 +0200 Subject: Rename ra_ide -> ide --- crates/ide/src/markup.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 crates/ide/src/markup.rs (limited to 'crates/ide/src/markup.rs') diff --git a/crates/ide/src/markup.rs b/crates/ide/src/markup.rs new file mode 100644 index 000000000..60c193c40 --- /dev/null +++ b/crates/ide/src/markup.rs @@ -0,0 +1,38 @@ +//! 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 for String { + fn from(markup: Markup) -> Self { + markup.text + } +} + +impl From for Markup { + fn from(text: String) -> Self { + Markup { text } + } +} + +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() + } + pub fn fenced_block(contents: &impl fmt::Display) -> Markup { + format!("```rust\n{}\n```", contents).into() + } +} -- cgit v1.2.3