Imagine a scenario in which a webpage contains the following structure:
<p>
<span class="1">Here's some text</span>
<span class="2">that the user</span>
<span class="3">could select.</span>
</p>
If a user decides to select the entire sentence (from "Here's" to "select."), the desired output should be "1" and "3".
In cases where only a portion of the sentence is highlighted (e.g., from "some" in span 1 to "the" in span 2), the expected return values are "1" and "2".
Is there an optimal method or strategy that can be employed for this task?
*Edit - It is worth noting that my goal is to find a solution that supports highlighting multiple non-overlapping sections of text simultaneously.
For instance: "Here's some text that" and "user could select." - If this type of selection is made, the result should be [[1,2],[2,3]].