Conversation
|
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])
}) |
|
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. 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: ...would colour each group of keywords in their own colour. See this topic for background on the basis of my patch: |
Added palette feature so that each match group can be styled differently.