diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs index bea29145..cebd325c 100644 --- a/fractal-gtk/src/appop/message.rs +++ b/fractal-gtk/src/appop/message.rs @@ -253,25 +253,7 @@ impl AppOp { let mut md_options = ComrakOptions::default(); md_options.hardbreaks = true; let mut md_parsed_msg = markdown_to_html(&msg, &md_options); - - // Removing wrap tag:
..
\n - let limit = md_parsed_msg.len() - 5; - let trim = match (md_parsed_msg.get(0..3), md_parsed_msg.get(limit..)) { - (Some(open), Some(close)) if open == "" && close == "
\n" => { - match md_parsed_msg.get(3..limit) { - // Don't trim if there's atag in the middle - Some(middle) => !middle.contains("
"), - None => true, - } - } - _ => false, - }; - if trim { - md_parsed_msg = md_parsed_msg - .get(3..limit) - .unwrap_or(&md_parsed_msg) - .to_string(); - } + md_parsed_msg = trim_p_tags(md_parsed_msg).to_owned(); if md_parsed_msg != msg { m.formatted_body = Some(md_parsed_msg); @@ -530,6 +512,20 @@ impl AppOp { } } +/// Trim paragraph tag from the start and end of a string if there's exactly one pair of +/// opening and closing tags in the string +fn trim_p_tags(md_message: &str) -> &str { + let limit = md_message.len().saturating_sub(5); + match ( + md_message.get(0..3), + md_message.get(3..limit), + md_message.get(limit..), + ) { + (Some("
"), Some(middle), Some("
\n")) if !middle.contains("") => middle, + _ => md_message, + } +} + /// This function opens the image, creates a thumbnail /// and populates the info Json with the information it has