Skip to content

Commit 87e0a6c

Browse files
committed
Add indentation logic
1 parent 906de3b commit 87e0a6c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

chatbot/templates/index.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,12 @@ <h2 class="popup-title">Session Conversation Thread</h2>
655655
if (data.voice === "user") {
656656
// Encode html tags and newlines
657657
data.update = data.update.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/[\n\r]/g, "<br>");
658-
// Preserve spaces at the beginning of the line
659-
data.update = data.update.replace(/ /g, "&nbsp;");
658+
// Escape the ` character
659+
data.update = data.update.replace(/`/g, "&grave;");
660+
// Convert tabs to 4 spaces, convert all two or more spaces to &nbsp;
661+
data.update = data.update.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;").replace(/ /g, "&nbsp;");
662+
// Convert any single &nbsp; sounded by characters on either side into a regular space ( )
663+
data.update = data.update.replace(/&nbsp;([^&])/g, " $1").replace(/([^&])&nbsp;/g, "$1 ");
660664
updateContainer.innerHTML += "<p class='user-text'>" + data.update + "</p>";
661665
}
662666

0 commit comments

Comments
 (0)