make a simple parser using regular expressions. Imported data in textarea did not replace characters successfully
only hope that imported data can replace characters;
matchArry [0] reported an error
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<textarea id="show" spellcheck="true">-sharp </textarea>
<input type="file" id="file1">
<input type="button" id="btn" onclick="rec()" value="">
<script>
var filein = document.getElementById("file1"),
showbox = document.getElementById("show");
filein.addEventListener("change", function () {
var file = filein.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
showbox.innerHTML = data;
};
reader.readAsText(file, "utf-8");
});
function rec() {
var textarea = document.getElementById("show");
textarea.innerHTML = main(textarea.value); //
}
function main(evt) {
var char = evt.split("\n");
var matchArry;
var html = "";
var len = char.length;
for (var i = 0; i < len; iPP) {
matchArry = char[i].match(/^-sharp\s/); //[""]
if (matchArry[0]) {
switch (matchArry[0]) { //
case "-sharp ":
html += "<h1>" + add(char[i].substring(2)) + "</h1>";
break;
default:
break;
}
} else {
html += "" + add(char[i]) + "
";
}
}
return html;
}
function add(str) {
str = str.replace(/\s/g, "");
return str;
}
</script>
</body>
</html>