advanced-mark.js v3 introduces several breaking changes from v2.x and from the original mark.js library. This page covers browser requirements, virtual DOM support, and a step-by-step migration guide for both upgrade paths.Documentation 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.
Browser requirements
advanced-mark.js v3 targets modern evergreen browsers (Chrome, Firefox, Safari, Edge). Support for very old browsers (including IE11) was dropped in v3. The CSS Custom Highlight API (highlight option) is used as a progressive enhancement: when the browser does not expose a global Highlight constructor, the library automatically falls back to wrapping matches in DOM elements. No code changes are required to support both cases.
JSDOM support
advanced-mark.js supports virtual DOM environments such as JSDOM (used by Jest, Node.js scripts, and SSR toolchains). Because JSDOM does not provide a globalwindow, you must pass your JSDOM window object explicitly via the window option:
Migrating from v2.x to v3
1. combineBy is now the default (formerly combinePatterns)
1. combineBy is now the default (formerly combinePatterns)
In v2, terms were highlighted one at a time by default. In v3,
combineBy: 100 is the default — terms are batched into combined RegExp patterns (up to 100 terms per pattern), drastically reducing the number of matching passes for large arrays.The old option name combinePatterns is still accepted for backward compatibility, but combineBy is preferred.If your code relied on single-term-at-a-time processing (e.g. relying on insertion order of mark elements matching exactly the array order, or avoiding highlights inside already-highlighted text), set combineBy: 1:A single combined pattern also prevents highlighting inside already-highlighted elements. If you need nested highlighting, use
combineBy: 1.2. Aborting execution: info.abort instead of info.execution.abort
2. Aborting execution: info.abort instead of info.execution.abort
In v2, the In v3, the The same change applies to the
filter and each callbacks received an info object with a nested execution sub-object. Aborting required:execution wrapper is removed. Set abort directly on the info object:each callback’s info parameter.3. separateGroups now requires the d flag
3. separateGroups now requires the d flag
In v2,
separateGroups: true worked with any RegExp. In v3, the d (indices) flag is required because the library uses RegExp.prototype.hasIndices to calculate group positions efficiently.RegExp.prototype.hasIndices (the d flag) is well established across modern browsers. If you must support browsers that lack d flag support, you cannot use separateGroups in v3.4. markRegExp() now requires the g flag
4. markRegExp() now requires the g flag
Prior to v3, passing a RegExp without the Update your RegExps to include
g flag to markRegExp() could produce incorrect results in certain patterns (e.g. look-behind workarounds that return empty matches would break the execution loop, causing subsequent matches to be missed).In v3, the g flag is required for correct behaviour. For backward compatibility, if the g flag is absent, advanced-mark.js recompiles the RegExp with g added and emits a console warning:g to silence the warning and avoid any future deprecation:5. cacheTextNodes option removed
5. cacheTextNodes option removed
The
cacheTextNodes option that existed in earlier v2 builds is removed in v3. It provided a small performance gain but was not compatible with several other options and added complexity that conflicted with CSS Custom Highlight API support.Remove any cacheTextNodes references from your options objects — the property is silently ignored if present, but relying on the caching behaviour it provided is no longer possible.6. offset property removed from filter callback
6. offset property removed from filter callback
In v2, the
filter callback’s info object included an offset property indicating the character position of the current match within its text node. This property is removed in v3.If your code reads info.offset (or filterInfo.offset) inside a filter callback, those reads will return undefined. You can derive positional information from the match property (match.index) when needed:If your use-case depended heavily on
offset, you will need to stay on advanced-mark.js v2. See the CHANGELOG for v2 release history.Migrating from mark.js
advanced-mark.js is a superset of the original mark.js library. The core API (mark(), markRegExp(), markRanges(), unmark()) and all original options are preserved, so most codebases can switch by replacing the package name:
- CSS Custom Highlight API support (
highlight,highlightName,staticRanges,rangeAcrossElements) - Shadow DOM traversal (
shadowDOM) separateWordSearch: 'preserveTerms'— preserve quoted phrases while splitting other wordsaccuracy: 'startsWith'— new accuracy modewildcards: 'withSpaces'— wildcards that match across whitespacemarkLinesoption inmarkRanges()for line-based rangeswrapAllRangesfor overlapping range/group markingcombineBy(formerlycombinePatterns) — batch term processing- JSDOM support via the
windowoption - Abort-on-demand via
info.abort = trueinfilterandeachcallbacks
The
RegExpCreator module that was previously exported from advanced-mark.js v2 has been removed from the npm package in v3. If you imported it directly, you will need to copy the relevant source or pin to v2.