1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use std::fmt; /// A markdown paragraph. /// /// A paragraph is a continuous text that is visually separated from its /// surrounding markdown elements. #[derive(Clone, Debug)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] pub struct Paragraph { /// The text inside the paragraph. pub text: String, } impl Paragraph { /// Creates a new paragraph with the given text. pub fn from(text: impl Into<String>) -> Self { Self { text: text.into() } } } impl fmt::Display for Paragraph { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "{}", self.text) } }