I am in the process of creating a web-based compiler using NodeJS. My main objective is to highlight syntax in different colors. For example, consider the following C code:
int var;
printf("%d",var);
In this code snippet, I would like the "int" and "printf" keywords to be colored differently. So far, I have implemented a feature that turns each letter red as it is typed.
<textarea rows="13" cols="150" id="code" name="code" placeholder="Type your code here" onfocus="if(this.value==''){
this.value='#include<stdio.h>\n' +
'int main(){\n' +
'return 0;\n' +
'}';
this.style.color='green';
}"
onkeyup="keyup()" onkeypress="pre()" onkeydown="down()" >
function keyup()
{
document.getElementById('code').style.color='green';
}
function pre()
{
document.getElementById('code').style.color='red';
}
function down()
{
document.getElementById('code').style.color='green';
}
I would appreciate any advice on how to assign different colors for standard I/O and data types.
Thank you in advance.