diff --git a/src/message_ast/convert_matrix.rs b/src/message_ast/convert_matrix.rs index 0dda458..2d5e091 100644 --- a/src/message_ast/convert_matrix.rs +++ b/src/message_ast/convert_matrix.rs @@ -23,10 +23,21 @@ pub fn convert_matrix(message: &str) -> MessageContent { | local_name!("b") | local_name!("em") | local_name!("i") - | local_name!("a") => { + | local_name!("s") + | local_name!("u") + | local_name!("a") + | local_name!("blockquote") => { parents.push(components); components = vec![]; } + + local_name!("span") => { + let attrs = element.attributes.borrow(); + if attrs.get("data-mx-spoiler").is_some() { + parents.push(components); + components = vec![]; + } + } _ => {} } } @@ -58,6 +69,12 @@ pub fn convert_matrix(message: &str) -> MessageContent { local_name!("em") | local_name!("i") => { construct_component!(MessageComponent::Italic) } + local_name!("s") => { + construct_component!(MessageComponent::Strikethrough) + } + local_name!("u") => { + construct_component!(MessageComponent::Underline) + } local_name!("a") => { if let Some(mut parent_components) = parents.pop() { let attrs = element.attributes.borrow(); @@ -73,6 +90,22 @@ pub fn convert_matrix(message: &str) -> MessageContent { components = parent_components; } } + local_name!("br") => { + components.push(MessageComponent::HardBreak); + } + local_name!("blockquote") => { + construct_component!(MessageComponent::BlockQuote) + } + local_name!("span") => { + let attrs = element.attributes.borrow(); + if let Some(spoiler_reason) = attrs.get("data-mx-spoiler") { + construct_component!(|inner| MessageComponent::Spoiler { + reason: (!spoiler_reason.is_empty()) + .then(|| spoiler_reason.to_string()), + content: inner, + }) + } + } _ => {} } } @@ -142,10 +175,9 @@ fn simple_matrix_parsing() { let html = r#"hello! <> example"#; - let ast = convert_matrix(html); assert_eq!( - ast, + convert_matrix(html), vec![ Bold(vec![ Plain("hello! ".to_string(),), @@ -159,3 +191,22 @@ fn simple_matrix_parsing() { ] ) } + +#[test] +fn spoiler_parsing() { + use MessageComponent::*; + + let html = r#"the whole island is populated by lesbians"#; + + assert_eq!( + convert_matrix(html), + vec![Spoiler { + reason: None, + content: vec![ + Plain("the ".to_string()), + Italic(vec![Plain("whole".to_string())]), + Plain(" island is populated by lesbians".to_string()) + ] + }] + ); +}