Skip to content

Commit a7939a4

Browse files
committed
use pre instead of innerHTML
1 parent a3cb2b8 commit a7939a4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

samples/agentic-strands/app/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
color: #888;
5858
font-style: italic;
5959
}
60+
pre {
61+
font-family: Arial, sans-serif;
62+
white-space: pre-wrap;
63+
}
6064
</style>
6165
</head>
6266
<body>
@@ -88,7 +92,10 @@ <h1>Library Assistant AI</h1>
8892
if (isUser) {
8993
messageDiv.textContent = text;
9094
} else {
91-
messageDiv.innerHTML = text;
95+
// Use a pre element to preserve new line formatting in agent messages
96+
const pre = document.createElement('pre');
97+
pre.textContent = text;
98+
messageDiv.appendChild(pre);
9299
}
93100
chatContainer.appendChild(messageDiv);
94101
chatContainer.scrollTop = chatContainer.scrollHeight;
@@ -123,7 +130,7 @@ <h1>Library Assistant AI</h1>
123130
// Remove loading indicator
124131
chatContainer.removeChild(loadingDiv);
125132

126-
const agentResponse = data.response.replace(/\n/g, '<br>');
133+
const agentResponse = data.response;
127134
// Display the agent's response
128135
addMessage(agentResponse, false);
129136

0 commit comments

Comments
 (0)