Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added palette feature #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

gingerbeardman
Copy link

Added palette feature so that each match group can be styled differently.

@jbr
Copy link
Owner

jbr commented Feb 19, 2013

This seems like fairly application-specific functionality unsuited for a library. Why is this preferable to the following, which requires no modification to the library:

var cyclingClasses = ['a', 'b', 'c', 'd'];
$('#content')
  .highlightRegex(/some regex/ig)
  .find('.highlight')
  .each(function(i) {
    $(this).addClass(cyclingClasses[i % cyclingClasses.length])
  })

@gingerbeardman
Copy link
Author

You're right, it is too specific, but I couldn't think of a better way to get my results.

Your solution is nice and neat, but it just cycles the colours for each highlight.
My solution colours each match group with the same colour.

I require all instances of a specific keyword have the same colour, as I am highlighting multiple keywords – actually groups of keywords – in the same document with one complex regular expression. I was doing it with multiple calls to highlightRegex, but that was too slow on long pages. So I arrived at my solution in order to do it in one call, and get match group specific colours.

For example:
/(Linux|Ubuntu)|(Windows|PC)|(Mac|Apple|iPad)/gi

...would colour each group of keywords in their own colour.

See this topic for background on the basis of my patch:
http://stackoverflow.com/questions/14912419/get-the-index-of-the-group-that-matched-in-a-regexp/14912534#14912534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants