treora / dom-highlight-range Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
In my application, I need to track additional information about each logical highlight. Today, it’s only possible to specify a class
attribute for a span
that’s created automatically. This is convenient, but not flexible enough. I’d like to be able to customize how the library constructs highlight wrappers to be able to add additional context to each highlight wrapper node. For example,
function renderAnnotation(annotation, range) {
highlightRange(range, function() {
var span = document.createElement('span');
span.classList.add('annotation');
span.dataset.annotationId = annotation.id;
return span;
});
}
This example adds a unique identifier for each logical highlight via a closure.
I tried to highlight a text till the middle of an anchor text by calling var removeHighlights = highlightRange(range). After that, I call removeHighlights(). The highlight will be removed. Then I called removeHighlights = highlightRange(range) again. The new highlight cannot reach the middle of anchor text.
Is it because of the DOM change? I can see your note for Range:
Note that as highlighting modifies the DOM, the range may be unusable afterwards
Are there any ways to preserve the highlight as intact?
Logical highlights that cross nodes are necessarily broken into physical segments to avoid overlapping markup. (That’s why this library is helpful!) In my highlightTemplate
callback I want to know which segment I’m working on, for example, to style the first or the last segment differently.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.