There are many ways to do this,.
First you need to know that the Javascript strings can be accessed as if they were an array, then you could check if the string starts with a > by simply accessing the index 0 of the string as follows.
if (conteudo[0] === ">") {}
I’m just checking by the character >, if you need this character to be wrapped in double quotes, then you can do 3 checks on the string, as follows.
if (conteudo[0] === '"' && conteudo[1] === '>' && conteudo[2] === '"'){}
This form is simple but it is a bad practice, so let’s try to check the whole group at once.
if (conteudo.indexOf('">"') === 0) {}
The indexof returns the index of the string where the substring passed as the argument to the function appears. In this case 0 means that it occurs at the beginning of the string.
This works a little better and is better to read and easier to keep the code, but it is still not the best solution because it does not take into account that your line can start with a space character, so let’s use regular expression to see how it would look.
var re = /^\s*">"/;
if (re.exec(conteudo)){}
Now we have a regular expression that checks whether the content variable starts with no, one or several spaces followed by ">", and we use the exec function to check whether the string contained in the content variable satisfies the condition of our regular expression. So I believe this is the best solution, even for you to create different tags in the future. Maybe I am wrong about the regular expression and there is a better way, our colleagues at Stackoverflow will help us with this but I believe that the path you have to tread to get what you want follow these clues I left here. Any doubt comment, and take into account that in the examples I use a variable called content, which should contain the content of your element p.
You want the line color or the line in green ?
– Diego Souza