Simple syntax higlighter

Developer
Size
3,865 Kb
Views
14,168

How do I make an simple syntax higlighter?

My first play with big and complicated(for a regex nub like me) and replacement using capture groups leave a comment and give it heart if you like its just my first try with this kind of thing. What is a simple syntax higlighter? How do you make a simple syntax higlighter? This script and codes were developed by Matheus Silva on 20 October 2022, Thursday.

Simple syntax higlighter Previews

Simple syntax higlighter - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>simple syntax higlighter</title> <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ .input{ color:blue; width: 20%; height: 40%;
}
body{ background-color: #2C3E50;
}
.code{ position: absolute; padding: 5px; width: 50%; height: 50%; color: black; background-color: #ECF0F1; margin: -5% 0 0 30%; font-family: 'Source Sans Pro', 'sans-serif'; font-size: 20px; overflow: scroll
}
span{ font-family: 'Source Sans Pro', 'sans-serif'; color: #ECF0F1;
}
.keyword{ color: #3A539B; font-wheight: bold;
}
.varn{ color: #E87E04; font-wheight: bold;
}
.function{ color: #2ECC71; font-weight: bold;
}
.string{ color: #96281B; font-wheight: bold;
}
.nl{ color: rgba(34, 49, 63, 0.2); font-wheight: bold;
}
.comment{ color: #87D37C;
}
.reset{ border-radius: 20px; border: none; background-color: #67809F; color: #A2DED0; padding: 9px; outline: none; transition: all .5s; position: absolute; top 55%;
}
.reset:hover{ border: 8px solid #22313F;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <span>write down your code: </span><br>
<textarea class="input"></textarea><br>
<button onclick="reset()" class="reset">Reset</button>
<div><pre class="code"></pre></div> <script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/90399/tokeniser.js'></script> <script src="js/index.js"></script>
</body>
</html>

Simple syntax higlighter - Script Codes CSS Codes

.input{ color:blue; width: 20%; height: 40%;
}
body{ background-color: #2C3E50;
}
.code{ position: absolute; padding: 5px; width: 50%; height: 50%; color: black; background-color: #ECF0F1; margin: -5% 0 0 30%; font-family: 'Source Sans Pro', 'sans-serif'; font-size: 20px; overflow: scroll
}
span{ font-family: 'Source Sans Pro', 'sans-serif'; color: #ECF0F1;
}
.keyword{ color: #3A539B; font-wheight: bold;
}
.varn{ color: #E87E04; font-wheight: bold;
}
.function{ color: #2ECC71; font-weight: bold;
}
.string{ color: #96281B; font-wheight: bold;
}
.nl{ color: rgba(34, 49, 63, 0.2); font-wheight: bold;
}
.comment{ color: #87D37C;
}
.reset{ border-radius: 20px; border: none; background-color: #67809F; color: #A2DED0; padding: 9px; outline: none; transition: all .5s; position: absolute; top 55%;
}
.reset:hover{ border: 8px solid #22313F;
}

Simple syntax higlighter - Script Codes JS Codes

var input = document.body.querySelector('.input');
var rst = document.body.querySelector('.reset');
var codeRender = document.body.querySelector('.code');
window.addEventListener ("load", function () { rst.addEventListener ("click", function (e) { var c = input.value; /*c = c.replace(/function (.+) \((.+)?\)/g, '<span class="function"> $1 </span> (<span class="varn">$2</span>)'); c = c.replace(/\n/g, '<br>'); c = c.replace(/\"(.+)?\"/g, '<span class="string">"$1"</span>'); c = c.replace(/var ([aA-zZ]+)/g, '<span class="keyword">var </span><span class="varn"> $1</span>'); c = c.replace(/(\/\/[^\n]+)/g, '<span class="comment">$1</span>'); c = c.replace(/(\/\*.+\*\/)/g, '<span class="comment">$1</span>'); c = c.replace(/\/\*(?:(?:.{0,}\n){0,}.{0,}(?:@Creator {0,}= {0,}\n{0,}([A-z0-9(){}\[\]\n, ]+);){1}(?:.{0,}\n){0,}.{0,})(?:(?:.{0,}\n){0,}.{0,}(?:@Contributors {0,}= {0,}\n{0,}([A-z0-9(){}\[\]\n, ]+);){1}(?:.{0,}\n){0,}.{0,})\*\//g, 'creator: $1\ncontributors: $2') c = c.replace(/(break|case|catch|const|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|let|new|return|switch|this|throw|try|typeof|var|void|while|with)/g, '<span class="keyword">$1</span>'); var instring = c; outstring = instring.replace(/01000001/g, "A"); outstring = instring.replace(/01000010/g, "B"); outstring = instring.replace(/01000011/g, "C"); outstring = instring.replace(/01000100/g, "D"); outstring = instring.replace(/01000101/g, "E"); outstring = instring.replace(/01000110/g, "F"); outstring = instring.replace(/01000111/g, "G"); outstring = instring.replace(/01001000/g, "H"); outstring = instring.replace(/01001001/g, "I"); outstring = instring.replace(/01001010/g, "J"); outstring = instring.replace(/01001011/g, "K"); outstring = instring.replace(/01001100/g, "L"); outstring = instring.replace(/01001101/g, "M"); outstring = instring.replace(/01001110/g, "N"); outstring = instring.replace(/01001111/g, "O"); outstring = instring.replace(/01010000/g, "P"); outstring = instring.replace(/01010001/g, "Q"); outstring = instring.replace(/01010010/g, "R"); outstring = instring.replace(/01010011/g, "S"); outstring = instring.replace(/01010100/g, "T"); outstring = instring.replace(/01010101/g, "U"); outstring = instring.replace(/01010110/g, "V"); outstring = instring.replace(/01010111/g, "W"); outstring = instring.replace(/01011000/g, "X"); outstring = instring.replace(/01011001/g, "Y"); outstring = instring.replace(/01011010/g, "Z"); outstring = instring.replace(/01100000/g, "`"); outstring = instring.replace(/01111110/g, "~"); outstring = instring.replace(/00110001/g, "1"); outstring = instring.replace(/00110010/g, "2"); outstring = instring.replace(/00110011/g, "3"); outstring = instring.replace(/00110100/g, "4"); outstring = instring.replace(/00110101/g, "5"); outstring = instring.replace(/00110110/g, "6"); outstring = instring.replace(/00110111/g, "7"); outstring = instring.replace(/00111000/g, "8"); outstring = instring.replace(/00111000/g, "9"); outstring = instring.replace(/00110000/g, "0"); outstring = instring.replace(/00100001/g, "!"); outstring = instring.replace(/01000000/g, "@"); outstring = instring.replace(/00100011/g, "#"); outstring = instring.replace(/00100100/g, "$"); outstring = instring.replace(/00100101/g, "%"); outstring = instring.replace(/01011110/g, "^"); outstring = instring.replace(/00100110/g, "&"); outstring = instring.replace(/00101010/g, "*"); outstring = instring.replace(/00101000/g, "("); outstring = instring.replace(/00101001/g, ")"); outstring = instring.replace(/01011111/g, "_"); outstring = instring.replace(/00101101/g, "-"); outstring = instring.replace(/00111101/g, "="); outstring = instring.replace(/00101011/g, "+"); outstring = instring.replace(/01011100/g, "/"); outstring = instring.replace(/01111100/g, "|"); outstring = instring.replace(/01111011/g, "{"); outstring = instring.replace(/01111101/g, "}"); outstring = instring.replace(/01011011/g, "["); outstring = instring.replace(/01011101/g, "]"); outstring = instring.replace(/00111100/g, "<"); outstring = instring.replace(/00111110/g, ">"); outstring = instring.replace(/00101111/g, "\\"); outstring = instring.replace(/00111111/g, "?"); outstring = instring.replace(/00101110/g, "."); outstring = instring.replace(/00101100/g, ","); outstring = instring.replace(/00100111/g, "'"); outstring = instring.replace(/00100010/g, "\""); outstring = instring.replace(/00111010/g, ":"); outstring = instring.replace(/00111011/g, ";"); outstring = instring.replace(/01100001/g, "a"); outstring = instring.replace(/01100010/g, "b"); outstring = instring.replace(/01100011/g, "c"); outstring = instring.replace(/01100100/g, "d"); outstring = instring.replace(/01100101/g, "e"); outstring = instring.replace(/01100110/g, "f"); outstring = instring.replace(/01100111/g, "g"); outstring = instring.replace(/01101000/g, "h"); outstring = instring.replace(/01101001/g, "i"); outstring = instring.replace(/01101010/g, "j"); outstring = instring.replace(/01101011/g, "k"); outstring = instring.replace(/01101100/g, "l"); outstring = instring.replace(/01101101/g, "m"); outstring = instring.replace(/01101110/g, "n"); outstring = instring.replace(/01101111/g, "o"); outstring = instring.replace(/01110000/g, "p"); outstring = instring.replace(/01110001/g, "q"); outstring = instring.replace(/01110010/g, "r"); outstring = instring.replace(/01110011/g, "s"); outstring = instring.replace(/01110100/g, "t"); outstring = instring.replace(/01110101/g, "u"); outstring = instring.replace(/01110110/g, "v"); outstring = instring.replace(/01110111/g, "w"); outstring = instring.replace(/01111000/g, "x"); outstring = instring.replace(/01111001/g, "y"); outstring = instring.replace(/01111010/g, "z"); outstring = instring.replace(/\n/g, ""); outstring = instring.replace(/1010/g, "\n");*/ codeRender.innerHTML = /*c*/tokenise(c); }, false); input.addEventListener ("keydown", function (e) { var keycode = e.keyCode || e.which; if (keycode == 9){ e.preventDefault(); var prec = input.value; input.value = prec + ' '; } }, false);
}, false);
/*function reset(){ input.value = ''; codeRender .innerHTML = '';
}*/
Simple syntax higlighter - Script Codes
Simple syntax higlighter - Script Codes
Home Page Home
Developer Matheus Silva
Username matheusxaviersi
Uploaded October 20, 2022
Rating 3
Size 3,865 Kb
Views 14,168
Do you need developer help for Simple syntax higlighter?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Matheus Silva (matheusxaviersi) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!