From a783abd0e333015e445baf5bb5bd4e7f71f955ca Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Wed, 3 Jun 2026 08:54:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9D=97=E5=8D=A0=E4=BD=8D=E7=AC=A6=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/channels/feishu.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/channels/feishu.rs b/src/channels/feishu.rs index c27cd36..de45e72 100644 --- a/src/channels/feishu.rs +++ b/src/channels/feishu.rs @@ -1931,15 +1931,24 @@ impl FeishuChannel { ); } + /// Restore all code block placeholders in the given text. + fn restore_code_blocks(text: &str, code_blocks: &[String]) -> String { + let mut result = text.to_string(); + for (i, cb) in code_blocks.iter().enumerate() { + result = result.replace(&format!("\x00CODE{}\x00", i), cb); + } + result + } + let mut elements: Vec = Vec::new(); let mut last_end = 0; for m in patterns.heading_re.find_iter(&protected) { - let before = &protected[last_end..m.start()].trim(); + let before = protected[last_end..m.start()].trim(); if !before.is_empty() { elements.push(serde_json::json!({ "tag": "markdown", - "content": before + "content": restore_code_blocks(before, &code_blocks) })); } @@ -1963,14 +1972,9 @@ impl FeishuChannel { let remaining = protected[last_end..].trim(); if !remaining.is_empty() { - // Restore code blocks - let mut final_content = remaining.to_string(); - for (i, cb) in code_blocks.iter().enumerate() { - final_content = final_content.replace(&format!("\x00CODE{}\x00", i), cb); - } elements.push(serde_json::json!({ "tag": "markdown", - "content": final_content + "content": restore_code_blocks(remaining, &code_blocks) })); }