Add constructor for markdown formatted messages behind a feature flag
Signed-off-by: Tilo Spannagel <development@tilosp.de>
This commit is contained in:
parent
cc355d8c77
commit
8c109d3c0a
@ -20,6 +20,7 @@ ruma-identifiers = { version = "=0.18.0-alpha.1", path = "../ruma-identifiers" }
|
||||
ruma-serde = { version = "0.3.0", path = "../ruma-serde" }
|
||||
serde = { version = "1.0.118", features = ["derive"] }
|
||||
serde_json = { version = "1.0.60", features = ["raw_value"] }
|
||||
pulldown-cmark = { version = "0.8", default-features = false, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
maplit = "1.0.2"
|
||||
@ -31,6 +32,7 @@ trybuild = "1.0.38"
|
||||
unstable-exhaustive-types = []
|
||||
unstable-pre-spec = []
|
||||
unstable-synapse-quirks = []
|
||||
markdown = ["pulldown-cmark"]
|
||||
|
||||
[[bench]]
|
||||
name = "event_deserialize"
|
||||
|
@ -479,6 +479,15 @@ impl TextMessageEventContent {
|
||||
Self { formatted: Some(FormattedBody::html(html_body)), ..Self::plain(body) }
|
||||
}
|
||||
|
||||
/// A convenience constructor to create a markdown message.
|
||||
#[cfg(feature = "markdown")]
|
||||
pub fn markdown(body: impl Into<String>) -> Self {
|
||||
let body = body.into();
|
||||
let mut html_body = String::new();
|
||||
pulldown_cmark::html::push_html(&mut html_body, pulldown_cmark::Parser::new(&body));
|
||||
Self::html(body, html_body)
|
||||
}
|
||||
|
||||
/// A convenience constructor to create a plain text message.
|
||||
#[deprecated = "Renamed to plain"]
|
||||
pub fn new_plain(body: impl Into<String>) -> Self {
|
||||
|
@ -63,3 +63,4 @@ unstable-synapse-quirks = [
|
||||
"ruma-common/unstable-synapse-quirks",
|
||||
"ruma-events/unstable-synapse-quirks",
|
||||
]
|
||||
markdown = ["ruma-events/markdown"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user