Show HN: A DOM text-selection highlight renderer
bowlingx.github.io
bowlingx.github.io
[{"startOffset":35,"endOffset":42,"startContainerPath":"html>body>div:nth-of-type(1)>div>p:nth-of-type(1);0","endContainerPath":"html>body>div:nth-of-type(1)>div>p:nth-of-type(1);0"},{"startOffset":32,"endOffset":7,"startContainerPath":"html>body>div:nth-of-type(1)>div>p:nth-of-type(1);10","endContainerPath":"html>body>div:nth-of-type(1)>div>p:nth-of-type(1)>code:nth-of-type(3);0"}]
One thing I think we might tweak for ourselves is to also store a copy of the string in there.
Thank you so much for sharing! I bet people would love an example showing how to use this to sync highlighted examples across user accounts. Hopefully, someone will do a Show HN of that!
Example:
<html>
<body>
<article id="myContextContainer">
<p>...</p>
</article></body>
</html>
If you add or change words and paragraphs of course, that would make the highlighting unstable. You could also restrict the marking to a specific paragraph only (and set the context accordingly). It always depends on the application this library is used for. But if anyone has a good idea how to compensate that I'm open for suggestions :)
Thank you for your feedback.
Could a WYSIWYG text editor be based on your library or does it have a completely different target?
But of course you may use it with any other library :)
I ended up rolling my own solution that worked for us, but one approach we tried out was looking at each selected element's parent. If the first and last element non-empty nodes in the parent were selected, then we also added the parent to the selection.
Two humble suggestions: - the glare effect in the text "Damn fast easy marking with serializable selections" made me think for a sec that this library was about different thing that I though. I'd remove that effect and mark the word "marking" in that text, so the slogan it's already a demo.
- If the library support marking in different colors show it in the demo would be awesome. or maybe in different advanced demo
marklib is especially useful and build for rendering incremental persisted selections and/or adding selections when other selections are already rendered (and though have modified the DOM). This is something rangy does not provide (at least that's my last information).
Also, any marking in the "code block" or the page title omits the spaces, which looks a little awkward.
Running Chrome 43.0.2357.124 on OS X
thank you :)
I'll try to explain it again giving another example:
if you highlight a word, and then you highlight the entire sentence containing that world, with your script it will highlight the word with a different color, with osx it will display like you didn't highlight the word prior to this
your behavior only happens when two highlighted segments cross over, but none of them contain the other.