mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-25 03:42:02 +00:00
address PR review: stricter HTML detection and fence label punctuation
This commit is contained in:
@@ -223,7 +223,8 @@ const runAiGeneration = async (requestFn) => {
|
||||
if (uuid !== currentConversationUUID.value) return
|
||||
const out = resp.data.data || ''
|
||||
// A model can ignore the HTML-output instruction; plain text pasted into the editor loses its line breaks.
|
||||
htmlContent.value = /<[a-z][\s\S]*>/i.test(out) ? out : convertTextToHtml(out)
|
||||
// The tag check must not match angle-bracketed plain text like "Contact <user@example.com>".
|
||||
htmlContent.value = /<\/?[a-z][a-z0-9]*(\s[^>]*)?\/?>/i.test(out) ? out : convertTextToHtml(out)
|
||||
} catch (error) {
|
||||
emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
|
||||
variant: 'destructive',
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ var (
|
||||
//go:embed queries.sql
|
||||
efs embed.FS
|
||||
|
||||
codeFenceOpenRe = regexp.MustCompile("^```[a-zA-Z0-9]*$")
|
||||
codeFenceOpenRe = regexp.MustCompile("^```[a-zA-Z0-9+#./_-]*$")
|
||||
|
||||
ErrInvalidAPIKey = errors.New("invalid API Key")
|
||||
ErrApiKeyNotSet = errors.New("api Key not set")
|
||||
|
||||
@@ -48,6 +48,16 @@ func TestStripCodeFence(t *testing.T) {
|
||||
in: "```<p>Hello,</p>\n<p>Thanks.</p>\n```",
|
||||
want: "```<p>Hello,</p>\n<p>Thanks.</p>\n```",
|
||||
},
|
||||
{
|
||||
name: "c++ fence unwrapped",
|
||||
in: "```c++\nint main() {}\n```",
|
||||
want: "int main() {}",
|
||||
},
|
||||
{
|
||||
name: "text/plain fence unwrapped",
|
||||
in: "```text/plain\nHello there.\n```",
|
||||
want: "Hello there.",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user