|
|
|
|
|
by albertoavila
5092 days ago
|
|
The 9-1 is the node hierarchy needed to find out where to start the highlighting, it's something like look for the 10nth child and then find the second child of that element (zero based index). If you have a more complex markup it becomes apparent, for example, if you selected something inside <p><span></span><strong><em>Text</em></strong></p> it would look like 0-1-0-0 The last part is exactly what you suggested, it's just the dom content substring. Another thing that it's not evident is that the selected text can transverse trough html elements, for example, start inside a span and end outside that span. Sadly that blog is not under my control, maybe i should try to blow the dust off that code and make a sample page. |
|
That said, if it's a Wordpress blog or something and the layout changes any existing links might not work.
Did you try encoding the text you want to highlight (and maybe the ordered instance) and then have the code search for it? I figure this might be less straight forward though as you'd need to strip HTML tags, find the text, and translate that back into modified Dom which could break many things.