new PrimitivoHighlighter(element [, options])
Creates a PrimitivoHighlighter instance for functionality specific to the original implementation.
Parameters:
Name | Type | Argument | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element |
HTMLElement | DOM element to which highlighted will be applied. |
||||||||||||||||||||||
options |
object |
<optional> |
additional options. Properties
|
- Source:
Methods
-
deserializeHighlights(json)
-
Deserializes highlights.
Parameters:
Name Type Description json
object JSON object with highlights definition.
- Source:
Throws:
exception when can't parse JSON or JSON has invalid structure.
Returns:
- array of deserialized highlights.
- Type
- Array
-
doHighlight(keepRange)
-
Highlights current range.
Parameters:
Name Type Description keepRange
boolean Don't remove range after highlighting. Default: false.
- Source:
-
flattenNestedHighlights(highlights)
-
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.
- Source:
-
getHighlights(params)
-
Returns highlights from given container.
Parameters:
Name Type Description params
Properties
Name Type Argument Description container
HTMLElement <optional>
return highlights from this element. Default: the element the
highlighter is applied to.andSelf
boolean <optional>
if set to true and container is a highlight itself, add container to
returned results. Default: true.grouped
boolean <optional>
if set to true, highlights are grouped in logical groups of highlights added
in the same moment. Each group is an object which has got array of highlights, 'toString' method and 'timestamp'
property. Default: false.- Source:
Returns:
- array of highlights.
- Type
- Array
-
highlightRange(range, wrapper)
-
Highlights range.
Wraps text of given range object in wrapper element.Parameters:
Name Type Description range
Range wrapper
HTMLElement - Source:
Returns:
- array of created highlights.
- Type
- Array
-
isHighlight(el)
-
Returns true if element is a highlight.
Parameters:
Name Type Description el
element to check.
- Source:
Returns:
- Type
- boolean
-
mergeSiblingHighlights(highlights)
-
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
- Source:
-
normalizeHighlights(highlights)
-
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.
- Source:
Returns:
- array of normalized highlights. Order and number of returned highlights may be different than
input highlights.
- Type
- Array
-
removeHighlights( [element])
-
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 Argument Description element
HTMLElement <optional>
element to remove highlights from
- Source:
-
serializeHighlights()
-
Serializes all highlights in the element the highlighter is applied to.
- Source:
Returns:
- stringified JSON with highlights definition
- Type
- string