I have long text I want to display in HTML
There are 2 areas I have to highlight, one is red and the other is green
Here is an example
“Last night, Israeli forces <mark style="background: #ff0000">attacked the hospital with tanks and destroyed all of the first floor.</mark> The damage was very bad,” Murad said, <mark style="background: #00ff00">speaking to Al Jazeera from the Indonesian</mark> capital Jakarta.
This is ok and no issues if both areas do not intersect
something like this {Text Red} [Text Green]
But if the 2 areas intersect here comes the problem.
Case 1
{Text [Red Text} Green]
“Last night, Israeli forces <mark style="background: #ff0000">attacked the hospital with tanks and destroyed all <mark style="background: #00ff00">of the first floor.</mark> The damage was very bad,” Murad said, speaking to Al Jazeera from the Indonesian</mark> capital Jakarta.
Case 2
{Text [Text Green] Red}
“Last night, Israeli forces <mark style="background: #ff0000">attacked the hospital with tanks and destroyed all <mark style="background: #00ff00">of the first floor.</mark> The damage was very bad,” Murad said, speaking to Al Jazeera from the Indonesian</mark> capital Jakarta.
as you can see the closing tag for both and is
how can I tell that the closeing tag is for the Red or Green mark?
2
Answers
The mark tag that you started is just going on that text but another mark recolors a piece at the end then the end just ends it.
You cannot. An element can only have one parent, so you can’t have an element that spans across two elements.
The closest would be to create 3 elements, the red one, a child green one, and a sibling green one. But both green ones won’t be the same element.
Note that even if you had different tag-names, the parser wouldn’t allow such a tree: