This is probably a lot simpler than I am thinking it is, but I figured I'd ask. My brain's not been at full speed for days now, and so I'm having a hard time logic-ing through this
What I'm trying to do:
I have a series of text blocks, stored as array elements in an HoA. I am scanning the text elements for regex pattern matches, and formatting the matching patterns with <span> tags. Because the patterns are user-defined, I don't know if any of them are going to overlap, and so I want to toss in a brief check to see if the matches overlap, and if so, do something about it.
How I thought I'd do it:
My first thought is to scan the text, and for each <span> increment an index value, and for each </span>, decrement it. If at any point the index reaches a number above 1, perform an action. Does that make sense to people?
Second, the actions I'm doing with the span tags is basically just text-highlighting. My thoughts then are, if there are no open span tags (i.e., index = 0), highlight with specified color. If there are open span tags, than close the previous span tag prematurely, open a new one, and make the text color of the overlap text the color of the highlighting from the last span tag, and the highlighting of this text that specified for the current span. At the location of the previous span's original endpoint, change the text back to black, and keep the highlighting.
Of course, I need to be prepared for the possibility of a third overlapping pattern, but I am not sure how to work that. I am also not sure of what to do if 2 different matches start at the same location in the text. Well, I know what I want to do - make the text color match 1 pattern and the highlight color match the other, but I am not sure how to do it.
As I said, this probably isn't very hard to do, but my brain hurts.
If someone could please just toss together a quick outline of code, I would gladly and very thankfully finesse it to make it work the way I want, I'm just not thinking clearly enough to figure out how to start.
Thanks,
Matt
In reply to Keeping track of html tags by mdunnbass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |