By default, if one highlighted range (or capturing group) overlaps with or is nested inside another, the inner range is skipped. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/angezid/advanced-mark.js/llms.txt
Use this file to discover all available pages before exploring further.
wrapAllRanges: true option removes this restriction — all ranges and groups are wrapped independently, regardless of nesting depth or overlap.
markRanges()—wrapAllRangeswraps every range whose start index falls within[0, context length], even if ranges overlap.markRegExp()— combinewrapAllRanges: truewithseparateGroups: trueto wrap capturing groups at any nesting level, including groups inside positive lookaround assertions.
Overlapping ranges with markRanges()
Supply an array of range objects — some of which overlap — and setwrapAllRanges: true. Use the each callback to inspect the original range object and apply different classes:
nested: true above) is preserved and passed back in each, making it easy to differentiate ranges without keeping a parallel lookup table.
Overlapping groups with markRegExp()
To wrap all capturing groups — regardless of whether they are nested inside another group — combineseparateGroups: true with wrapAllRanges: true:
wrapAllRanges, wrapping group 1 would cause group 2 (which is nested inside group 1) to be ignored. With wrapAllRanges: true both are wrapped and you can style them independently.
Capturing groups inside lookaround assertions
wrapAllRanges: true also enables wrapping of capturing groups that appear inside positive lookaround assertions ((?=…) and (?<=…)). This is not possible without the option because lookarounds produce zero-width matches and their groups would otherwise be skipped as overlapping.
Next/Previous navigation with overlapping matches
Standard “start element” navigation techniques break down with overlapping marks because a single logical match can produce multiple<mark> elements at different DOM positions. The recommended approach is to store a numeric match identifier on each element using data-markjs, then query by that identifier on navigation:
info.count increments once per match, not once per mark element, so every <mark> produced by the same regex match receives the same data-markjs value. This makes it trivial to select all elements for a given logical match.Performance considerations
wrapAllRanges is implemented by maintaining a sorted array of wrapped positions. Each new wrap inserts two index entries, requiring array copying and memory allocation proportional to the number of existing overlapping marks.
The table below was measured on a 1 MB file containing 20,800 text nodes (run on a slow processor with advanced-mark.js v2 — the ratios matter more than the absolute times):
| Option | 2,500 marked groups | 29,000 marked groups |
|---|---|---|
wrapAllRanges: true | ~120 ms | ~710 ms |
wrapAllRanges: false | ~70 ms | ~310 ms |