javascript - Changing color of lines that begin with * in a multi-line <div> tag -


i have written program works syntax highlighter. problem left language should specify * sign comment, if appear @ beginning of each line. however, if appear after other character, considered multiplication operator , not comment sign.

the code written in tag. program has check content of div , change color of each line if begins *. has bugged me appreciated.

for example, have following code block:

<div> code  * comment notcomment = 10 * 10  </div> 

in example, second line should turn comment whereas third line not comment.

if each line of code begins separate <div> tag, solution easy. since each tag can include chunk of code, becomes troublesome.

something this:

const elements = document.queryselectorall('div');    [...elements].foreach(el => {    if (el.textcontent.startswith('*')) {      el.classlist.add('comment');    }  });
.comment {    color: lightgray;  }
<div>line 1</div>  <div>line 2</div>  <div>* line 3</div>  <div>* line 4</div>  <div>line * 5</div>


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -