Mrkr is a simple utility to apply arbitrary styles to highlighted text either using the native cursor or programmatically with a set of number offsets.
# npm
npm i mrkrjs
# yarn
yarn add mrkrjs
import Mrkr from 'mrkrjs';
// Create mrkr instance
const mrkr = new Mrkr(document.body, 'highlight');
A target container element to apply highlighting to.
Note: Any HTMLElement works as a container, however using the
body
element can result in slower highlighting with larger pages.
The class name to apply to highlighted elements.
An object containing intialization parameters. The possible options are:
options.minimum
number
Default: undefined
The minimum amount of text that must be selected to apply highlights.
options.maximum
number
Default: undefined
The maximum amount of text that can be selected to apply highlights.
options.overlap
boolean
Default: false
Allow overlapping highlights.
options.onSelection
(e, data) => void
Default: undefined
Callback that's fired on selection with the cursor.
Enables the highlighter.
Disables the highlighter.
Clears a specific range of highlighted text if an array is passed, otherwise clears all highlighted text.
offsetTargets
:
{
startOffset: number;
endOffset: number;
}[]
Sets the current className
applied to highlighted text.
className
: string
Gets an array of data about the highlighted blocks of text.
{
startOffset: number;
endOffset: number;
text: string;
node: Text[];
}[]
Set the highlighter's current container element.
element
: HTMLElement
Applies the highlight class to the currently selected text.
{
startOffset: number;
endOffset: number;
text: string;
node: Text[];
}[]
Applies the highlight class to the specified range of text offsets.
startOffset
: number
endOffset
: number
{
startOffset: number;
endOffset: number;
text: string;
node: Text[];
}[]
Gets the current active state of the selection highlighter.
boolean
Toggles the current active state of the selection highlighter or sets the passed enabled state.
isEnabled
: boolean