fix hyperlinks getting lost across AI features

AI grammar fix rewrote the draft as plain text, so links in the reply box were dropped. It now sends the editor HTML and asks the model to keep tags. Conversation transcripts, the AI agent history and copilot context also stripped link URLs when converting HTML to text, so the model never saw them. They now keep links as "text ( url )".
This commit is contained in:
Abhinav Raut
2026-07-31 16:08:19 +05:30
parent 6496cdec28
commit 72c3f29830
10 changed files with 190 additions and 15 deletions
+31
View File
@@ -296,3 +296,34 @@ func TestSplitName(t *testing.T) {
})
}
}
func TestHTML2TextWithLinks(t *testing.T) {
tests := []struct {
name string
html string
want string
}{
{
name: "link with distinct text keeps url",
html: `<p>See <a href="https://example.com/guide">the guide</a> for steps.</p>`,
want: "See the guide ( https://example.com/guide ) for steps.",
},
{
name: "link text equal to url not duplicated",
html: `<p><a href="https://example.com">https://example.com</a></p>`,
want: "https://example.com",
},
{
name: "plain text unchanged",
html: `<p>No links here.</p>`,
want: "No links here.",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HTML2TextWithLinks(tt.html); got != tt.want {
t.Errorf("got %q, want %q", got, tt.want)
}
})
}
}