From fd102fb47b95c91bf03b8759eadefc6655199391 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Wed, 28 Oct 2026 13:44:26 +0100 Subject: [PATCH] Start a new paragraph when an HTML block tag opens in paste Found while testing crates/engine/src/cmd/richclip.rs:121-170 (html_to_body, opening-tag handling; is_block at :190) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/cmd/richclip.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/engine/src/cmd/richclip.rs b/crates/engine/src/cmd/richclip.rs index 5b9eaf6d..d5bc135f 100644 --- a/crates/engine/src/cmd/richclip.rs +++ b/crates/engine/src/cmd/richclip.rs @@ -123,6 +123,9 @@ pub fn html_to_body(html: &str) -> Option { } continue; } + if is_block(&name) { + new_para(&mut paragraphs); + } if is_break(&name) { new_para(&mut paragraphs); continue; @@ -368,6 +371,15 @@ fn fold(s: &str) -> String { mod tests { use super::*; + #[test] + fn text_before_opening_block_tag_is_separate_paragraph() { + for tag in ["div", "p", "li", "h1"] { + let body = html_to_body(&format!("Hello<{tag}>world")).unwrap(); + let texts: Vec = body.paragraphs.iter().map(|p| p.runs.iter().map(|r| r.text.as_str()).collect()).collect(); + assert_eq!(texts, ["Hello", "world"], "{tag}"); + } + } + #[test] fn multibyte_after_ampersand_is_kept() { let text = "é".repeat(20);