Suppose you have a word "day" in 100 sentences in your document. You can change the color of that word in the following way:
<span style="color: #ff0000"> day </span>
The problem is that you need to do it 100 times. I am using Django and I want to do it inside template with for loop. So, my problem is now to change the color of a string inside some sentence that I don't know what it will be. I tried with something like:
def colored(sentence, string, color):
if string not in sentence:
return sentence
else:
colored_string = f'<span style="color: {color}"> {string} </span>'
return colored_string.join(sentence.split(string))
I thought that that will give me colored variable string, but that wasn't the case. It just returned the string '....<span....' without any including the same stuff. It just like it didn't recognized html at all. What is the correct way of solving the same problem?