简体   繁体   中英

how to color a word in nodeJs

I a trying to develop a web based compiler using nodeJS. My goal is to color each syntax. Such as for the following C code:

int var;
printf("%d",var);

I want to color the "int" and printf here. I have done following code until today where each letter has turned to red during typing.

<textarea rows="13" cols="150" id="code" name="code" placeholder="do ypur 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 am looking for advices to put differnt , colors for standard i/o, data types.

Thank you in advance.

You can use colors package to select color for text and background.

Install package

npm install colors --save

Usage

var colors = require('colors');
console.log('hello'.green); // outputs green text 

OR

var colors = require('colors/safe');
console.log(colors.green('hello')); // outputs green text 

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM