diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_ide/src/markup.rs | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_ide/src/markup.rs')
-rw-r--r-- | crates/ra_ide/src/markup.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/crates/ra_ide/src/markup.rs b/crates/ra_ide/src/markup.rs new file mode 100644 index 000000000..60c193c40 --- /dev/null +++ b/crates/ra_ide/src/markup.rs | |||
@@ -0,0 +1,38 @@ | |||
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. | ||
6 | use std::fmt; | ||
7 | |||
8 | #[derive(Default, Debug)] | ||
9 | pub struct Markup { | ||
10 | text: String, | ||
11 | } | ||
12 | |||
13 | impl From<Markup> for String { | ||
14 | fn from(markup: Markup) -> Self { | ||
15 | markup.text | ||
16 | } | ||
17 | } | ||
18 | |||
19 | impl From<String> for Markup { | ||
20 | fn from(text: String) -> Self { | ||
21 | Markup { text } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | impl fmt::Display for Markup { | ||
26 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
27 | fmt::Display::fmt(&self.text, f) | ||
28 | } | ||
29 | } | ||
30 | |||
31 | impl 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{}\n```", contents).into() | ||
37 | } | ||
38 | } | ||