//! Parse various text markup formats.
//!
//! Each module is optional and relies on a feature.
#[cfg(feature = "markdown")]
pub mod markdown;
#[cfg(feature = "markdown")]
pub use self::markdown::MarkdownText;
use owning_ref::OwningHandle;
use owning_ref::StringRef;
use std::ops::Deref;
use theme::Style;
use utils::span::{StSpannedString;
/// A parsed string with markup style.
///
/// Contains both the source string, and parsed information indicating the
/// style to apply.
pub type StyledString = SpannedString<Style>;
pub type StyledIndexedSpan = IndexedSpan<Style>;
impl SpannedString<Style> {
/// Returns a plain StyledString without any style.
///
/// > You got no style, Dutch. You know that.
pub fn plain<S>(content: S) -> Self
where
S: Into<String>,
{
Self::styled(content, Style::none())
}
/// Creates a new `StyledString` using a single style for the entire text.
pub fn styled<S, T>(content: S, style: T) -> Self
where
S: Into<String>,
T: Into<Style>,
{
let content = content.into();
let spans = vec![
StyledIndexedSpan {
content: IndexedCow::Borrowed {
start: 0,
end: content.len(),
},
style: style.into(),
},
];
Self::new(content, spans)
}
/// Appends the given plain text to `self`.
pub fn append_plain<S>(&mut self, text: S)
where
S: Into<String>,
{
self.append(Self::plain(text));
}
/// Appends `text` to `self`, using `style`.
pub fn append_styled<S, T>(&mut self, text: S, style: T)
where
S: Into<String>,
T: Into<Style>,
{
self.append(Self::styled(text, style));
}
/// Appends the given plain text to `self`.
pub fn append_plain<S>(&mut self, text: S)
where
S: Into<String>,
{
self.append(Self::plain(text));
}
/// Appends `text` to `self`, using `style`.
pub fn append_styled<S, T>(&mut self, text: S, style: T)
where
S: Into<String>,
T: Into<Style>,
{
self.append(Self::styled(text, style));
}
}