0
Any way to select specific text in paragraph to be styled?
I want evertyhing between "<" and ">" to be yellow for example, how do I do that?
5 Antworten
+ 1
Something like this ,
https://code.sololearn.com/WnVRy8S1A0Fa/?ref=app
+ 1
Karak10 Boolean is a function that has a default value of False , so it removes all the empty characters from the array. Remove ".filter(Boolean) " and console.log the text , you will understand what i mean.
And since it is an array, so need to index the first item which i corrected.
0
Abhay what does filter(Boolean) do?
0
/*
are you trying to make some code syntax hilighting?
if so, you should use:
*/
src = '<tag foo="bar">• content</tag>';
esc = src.replace(/[<&]/g, c => '&'+{'<':'lt','&':'amp'}[c]+';');
// esc == '<tag foo="bar">&bull content</tag>';
html = esc.replace(/<(.+?)>/g,'<<span style="color:red">$1</span>>');
// html == '<<span style="color:red">tag foo="bar"</span>>&bull content<<span style="color:red">/tag</span>>';
document.write(html);
0
I have been keeping notes of stuff I learn and I write down my code above each project I make so that I can easily read it any time, I have been doing that a long time now and I have been using a green background but I wanted to make it a little more readable by making it colorful like in VSC editor for example. I think I found a way to do that, it seems to be working well and I think it's flexible too:
https://code.sololearn.com/WgX3Q77Gxk5V/?ref=app