Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I getcha.cthe code will work if the blog author changes the layout still? That is, the children aspect works and doesn't need to be tweaked for each layout and works for all correct HTML?

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.



The code looks for the post container element, so, if the layout is changed you would need to change at most just the parent css selector, and old links would still be working, but would stop working if the post is edited, i.e. a new paragraph was added.

It wouldn't be a problem to encode the selected text and look for it, actually that's how the selecting works, i get the selected text and look for it on the document,striping html tags and finding all the elements which contains part of the selected string, only then i enconde the relative position on the dom tree of the node to be able to look for it later (The 9-1 stuff).

The problem with encoding the text is that the url could get pretty long pretty easily, but that could be solved if the server stored it and you got only a hash to look it up, that would have the benefit of the highligting links to keep working if the post is edited partially.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: