feat: 添加恢复代码块占位符的功能,优化文本处理逻辑
This commit is contained in:
parent
15dfc48837
commit
a783abd0e3
@ -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<serde_json::Value> = 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)
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user