mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-10-25 17:36:43 +08:00
Merge pull request #1273 from chenhg5/agent/cc-connect/dev-claudecode/pr508-hr
fix(feishu): extract hr element as standalone '---' in quoted posts (fixes #508)
This commit is contained in:
2 files changed
+48
No files matched your search
@@ -2817,6 +2817,18 @@ func extractPostPlainText(content string) string {
|
||||
lang := elem.Language
|
||||
line = append(line, "```"+lang+"\n"+elem.Text+"\n```")
|
||||
}
|
||||
case "hr":
|
||||
// Lark posts render an `hr` element as a horizontal rule;
|
||||
// map it to a standalone markdown separator on its own line
|
||||
// so the agent (and downstream markdown renderers) can
|
||||
// recognize the boundary. We flush any pending line text
|
||||
// first so the rule is not glued to surrounding text
|
||||
// (issue #508; related #470/#472).
|
||||
if len(line) > 0 {
|
||||
parts = append(parts, strings.Join(line, ""))
|
||||
line = line[:0]
|
||||
}
|
||||
parts = append(parts, "---")
|
||||
}
|
||||
}
|
||||
if len(line) > 0 {
|
||||
|
||||
@@ -1014,6 +1014,42 @@ func TestExtractPostPlainText_CodeBlock(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestExtractPostPlainText_HrTag is a regression test for issue #508
|
||||
// (related #470/#472). Lark posts use the `hr` element to mark a
|
||||
// horizontal rule boundary between sections of a quoted post; the
|
||||
// extractor must surface it as a standalone `---` so the agent
|
||||
// understands the section break instead of silently dropping it.
|
||||
func TestExtractPostPlainText_HrTag(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
content string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "hr_alone",
|
||||
content: `{"content":[[{"tag":"hr"}]]}`,
|
||||
want: "---",
|
||||
},
|
||||
{
|
||||
name: "hr_after_text",
|
||||
content: `{"content":[[{"tag":"text","text":"before"},{"tag":"hr"},{"tag":"text","text":"after"}]]}`,
|
||||
want: "before\n---\nafter",
|
||||
},
|
||||
{
|
||||
name: "hr_between_paragraphs",
|
||||
content: `{"content":[[{"tag":"text","text":"first"}],[{"tag":"hr"}],[{"tag":"text","text":"second"}]]}`,
|
||||
want: "first\n---\nsecond",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := extractPostPlainText(tc.content); got != tc.want {
|
||||
t.Errorf("extractPostPlainText(%q) = %q, want %q", tc.content, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func strPtr(s string) *string { return &s }
|
||||
|
||||
func TestStripMentions(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user