I am working on a website where a user can input a message that is sent to another user. I want to implement Markdown so the user can use markdown on the message to be able to bold the message and other markdown options. I want to implement this but I want to make sure that xss cannot happen and .innerHTML seems like it will cause issues. I am not using node. Someone suggested using https://ourcodeworld.com/articles/read/396/how-to-convert-markdown-to-html-in-javascript-using-remarkable but it appears to be written in node and if it can be used directly in the js of a browser I have been unable to get it to work even copy pasting the code on the examples has not worked.
function OnKeyDownOne(event) {
if (event.which===13) {
let textarea = document.getElementById("textareaOne").value;
document.getElementById("textareaOne").value = "";
console.log(textarea);
document.getElementById("textOne").innerHTML = textarea;
}
}
function OnKeyDownTwo(event) {
if (event.which===13) {
let textarea = document.getElementById("textareaTwo").value;
document.getElementById("textareaTwo").value = "";
console.log(textarea);
document.getElementById("textTwo").innerHTML = textarea.replace(" *", "<b> ").replace("* ", " </b>");
}
}
<textarea id="textareaOne" onkeydown="OnKeyDownOne(event)"></textarea>
<p id="textOne"></p>
<textarea id="textareaTwo" onkeydown="OnKeyDownTwo(event)"></textarea>
<p id="textTwo"></p>