per-pattern className when passing an Array of strings to mark
See original GitHub issueIs your feature request related to a problem? Please describe. Different patterns marked using different classes.
Describe the solution you’d like
If I want to mark “E” in red and “A” in blue, the only solution is to initialize mark.js
twice with two different regexps and a distinct opt.className
for each. But with possibly up to 40 such patterns, mark.js
may (likely?) be inefficient (didn’t tried yet) and may have to proceed many more DOM nodes and miss the opportunity of significant optimization logics.
Still:
mark.js
already supports multiple patterns (even if it compile them as one regex)mark.js
seems to care greetly about capturing groups index
Describe a potential solution approach
I think mark.js
could (possibly?) keep track of the capturing group index in order to map them to metadata (eg: className) associated with the initial pattern so that during the replacing phase, wrapGroups()
(and inner functions) could be passed the per-regexp class/element override) so that wrapRangeInTextNode
is not stuck with only opt.className
.
With this feature, mark()
would possibly accept an object like {patternA: className, patternB: className2}
or {patternA: {…optsA}}`. This also open the door at whether a list of patterns (instead of mere strings) could be passed with each having its own className…
Additional context
- Use-case is for coloring characters (and/or adding images nearby of particular strings) for educational / mind-training purposes.
- #450 probably needs to be merged first before any further modification is attempted to
src/lib/mark.js
.
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top GitHub Comments
It seems you are using diacritics. The current term can be gotten from filter callback:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.