Serialize/deserialize Range in HTML.
Cares about serialization/deserialization only.
Highlighting of text is a matter of your implementation.
- User wants to highlight text in HTML.
- User wants to see the highlighted text in HTML on next page load (application should store Range representation and apply after page load).
Comming soon.
- Create array of atomic range objects only with text inside from input range.
- Create HTML selector from array of atomic ranges as JSON.
- Serialization.
- Compression.
- Encoding.
- Decoding.
- Decompression.
- Deserialization.
- JSON parse.
- Array of Range DOM.
import Rangee from './Rangee';
const rangee = new Rangee({ document });
let rangeStorage = "";
document.querySelector("#save").addEventListener("click", () => {
const selection = document.getSelection();
if (selection && selection.rangeCount > 0) {
const range = selection.getRangeAt(0);
if (range) {
const rangeRepresentation = rangee.serializeAtomic(range);
rangeStorage = rangeRepresentation;
// there you have rangee output (range representation in base64) and you can store somewhere
}
}
})
...
document.querySelector("#load").addEventListener("click", () => {
const rangeRepresentation = rangeStorage; // earlier stored range representation
const ranges = rangee.deserilaizeAtomic(rangeRepresentation);
// highlight range (sub ranges - beacause of HTML structure)
ranges.forEach(range => {
const highlight = document.createElement("mark")
range.surroundContents(highlight);
})
})
![]() IE11 / Edge |
![]() Firefox |
![]() Chrome |
![]() Safari |
![]() Opera |
---|
- Basic functionality
- Implement deflate compression
- Prepare to npm
- Create table of supported browsers
- Your idea?