Giter Site home page Giter Site logo

dom-highlight-range's People

Contributors

treora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dom-highlight-range's Issues

The highlight will have a loss if the range is in the middle of an anchor tag

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.

dom_highlight_range_issue

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?

Customize the element used for highlighting

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.

Expose highlight index to node template functions

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.