new PrimitivoHighlighter(element, optionsopt)
- Source:
Creates a PrimitivoHighlighter instance for functionality specific to the original implementation.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element |
HTMLElement | DOM element to which highlighted will be applied. |
||||||||||||||||||||||
options |
object |
<optional> |
additional options. Properties
|
Methods
deserializeHighlights(json) → {Array}
- Source:
Deserializes highlights.
Parameters:
Name | Type | Description |
---|---|---|
json |
object | JSON object with highlights definition. |
Throws:
exception when can't parse JSON or JSON has invalid structure.
Returns:
- array of deserialized highlights.
- Type
- Array
doHighlight(keepRange)
- Source:
Highlights current range.
Parameters:
Name | Type | Description |
---|---|---|
keepRange |
boolean | Don't remove range after highlighting. Default: false. |
flattenNestedHighlights(highlights)
- Source:
Flattens highlights structure.
Note: this method changes input highlights - their order and number after calling this method may change.
Parameters:
Name | Type | Description |
---|---|---|
highlights |
Array | highlights to flatten. |
getHighlights(params) → {Array}
- Source:
Returns highlights from given container.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Properties
|
Returns:
- array of highlights.
- Type
- Array
highlightRange(range, wrapper) → {Array}
- Source:
Highlights range.
Wraps text of given range object in wrapper element.
Parameters:
Name | Type | Description |
---|---|---|
range |
Range | |
wrapper |
HTMLElement |
Returns:
- array of created highlights.
- Type
- Array
isHighlight(el) → {boolean}
- Source:
Returns true if element is a highlight.
Parameters:
Name | Type | Description |
---|---|---|
el |
element to check. |
Returns:
- Type
- boolean
mergeSiblingHighlights(highlights)
- Source:
Merges sibling highlights and normalizes descendant text nodes.
Note: this method changes input highlights - their order and number after calling this method may change.
Parameters:
Name | Type | Description |
---|---|---|
highlights |
normalizeHighlights(highlights) → {Array}
- Source:
Normalizes highlights. Ensures that highlighting is done with use of the smallest possible number of
wrapping HTML elements.
Flattens highlights structure and merges sibling highlights. Normalizes text nodes within highlights.
Parameters:
Name | Type | Description |
---|---|---|
highlights |
Array | highlights to normalize. |
Returns:
- array of normalized highlights. Order and number of returned highlights may be different than
input highlights.
- Type
- Array
removeHighlights(elementopt)
- Source:
Removes highlights from element. If element is a highlight itself, it is removed as well.
If no element is given, all highlights all removed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
element |
HTMLElement |
<optional> |
element to remove highlights from |
serializeHighlights() → {string}
- Source:
Serializes all highlights in the element the highlighter is applied to.
Returns:
- stringified JSON with highlights definition
- Type
- string