diff --git a/src/views/channel.ejs b/src/views/channel.ejs
index 496316a..fba0ca2 100644
--- a/src/views/channel.ejs
+++ b/src/views/channel.ejs
@@ -121,6 +121,7 @@ along with this program. If not, see .-->
<%- include('partial/scripts', {user}); %>
+
diff --git a/www/js/channel/chat.js b/www/js/channel/chat.js
index fc2ee66..3e31d13 100644
--- a/www/js/channel/chat.js
+++ b/www/js/channel/chat.js
@@ -24,6 +24,7 @@ class chatBox{
//clickDragger object
this.clickDragger = new canopyUXUtils.clickDragger("#chat-panel-drag-handle", "#chat-panel-div");
+ this.chatPreprocessor = new chatPreprocessor();
//Element Nodes
this.chatPanel = document.querySelector("#chat-panel-div");
@@ -106,7 +107,8 @@ class chatBox{
chatBody.innerHTML = chat.msg;
chatEntry.appendChild(chatBody);
- this.chatBuffer.appendChild(chatEntry);
+
+ this.chatBuffer.appendChild(this.chatPreprocessor.preprocess(chatEntry));
}
async send(event){
diff --git a/www/js/channel/chatPreprocessor.js b/www/js/channel/chatPreprocessor.js
new file mode 100644
index 0000000..fcdb7b2
--- /dev/null
+++ b/www/js/channel/chatPreprocessor.js
@@ -0,0 +1,65 @@
+class chatPreprocessor{
+ constructor(){
+ }
+
+ preprocess(chatEntry){
+ //Set current chat nodes
+ this.chatEntry = chatEntry;
+ this.chatBody = this.chatEntry.querySelector(".chat-entry-body");
+
+ //Split the chat body into an array of objects representing each word
+ //We could pass this through arguments but these functions wont be very interoperable anyways since they expect a purpose-made hashtable
+ this.splitBody();
+
+ //Inject whitespace into un-processed words
+ this.addWhitespace();
+
+ //Inject the pre-processed chat into the chatEntry node
+ this.injectBody();
+ //Return the pre-processed node
+ return this.chatEntry;
+ }
+
+ splitBody(){
+ //Create an empty array to hold the body
+ this.bodyArray = [];
+ //Split string by words
+ const splitString = this.chatBody.innerHTML.split(/(\W)+/g); //Group not-words together
+
+ //for each word in the splitstring
+ splitString.forEach((string) => {
+ //create a word object
+ const wordObj = {
+ string: string,
+ type: "word"
+ }
+
+ //Add it to our body array
+ this.bodyArray.push(wordObj);
+ });
+ }
+
+ injectBody(){
+ //Create empty array to hold strings
+ var stringArray = [];
+
+ //Extract strings into the empty array
+ this.bodyArray.forEach((wordObj) => {
+ stringArray.push(wordObj.string);
+ });
+
+ //Join the strings to fill the chat entry
+ this.chatBody.innerHTML = stringArray.join("");
+ }
+
+ addWhitespace(){
+ //for each word object in the body
+ this.bodyArray.forEach((wordObj, index) => {
+ //if the word object hasn't been pre-processed elsewhere
+ if(wordObj.type == "word"){
+ //Add invisible whitespace in-between characters to keep it from breaking page layout
+ this.bodyArray[index].string = wordObj.string.split("").join("ㅤ");
+ }
+ });
+ }
+}
\ No newline at end of file