# PrimitivoHighlighter

#### new PrimitivoHighlighter(element, optionsopt)

Source:
  - highlighters/primitivo.js, line 23

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
Name | Type | Description
--- | --- | ---
`color` | string | highlight color.
`highlightedClass` | string | class added to highlight, 'highlighted' by default.
`contextClass` | string | class added to element to which highlighter is applied, 'highlighter-context' by default.
`onRemoveHighlight` | function | function called before highlight is removed. Highlight is passed as param. Function should return true if highlight should be removed, or false - to prevent removal.
`onBeforeHighlight` | function | function called before highlight is created. Range object is passed as param. Function should return true to continue processing, or false - to prevent highlighting.
`onAfterHighlight` | onAfterHighlightCallbackV1 | function called after highlight is created. Array of created wrappers is passed as param.

### Methods

#### deserializeHighlights(json) → {Array}

Source:
  - highlighters/primitivo.js, line 417

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:
  - highlighters/primitivo.js, line 263

Highlights current range.

##### Parameters:

Name | Type | Description
--- | --- | ---
`keepRange` | boolean | Don't remove range after highlighting. Default: false.

#### flattenNestedHighlights(highlights)

Source:
  - highlighters/primitivo.js, line 143

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:
  - highlighters/primitivo.js, line 345

Returns highlights from given container.

##### Parameters:

Name | Type | Description
--- | --- | ---
`params` |  | ###### Properties
Name | Type | Attributes | 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.

##### Returns:

- array of highlights.

Type
  Array

#### highlightRange(range, wrapper) → {Array}

Source:
  - highlighters/primitivo.js, line 53

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:
  - highlighters/primitivo.js, line 362

Returns true if element is a highlight.

##### Parameters:

Name | Type | Description
--- | --- | ---
`el` |  | element to check.

##### Returns:

Type
  boolean

#### mergeSiblingHighlights(highlights)

Source:
  - highlighters/primitivo.js, line 229

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:
  - highlighters/primitivo.js, line 118

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:
  - highlighters/primitivo.js, line 296

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:
  - highlighters/primitivo.js, line 371

Serializes all highlights in the element the highlighter is applied to.

##### Returns:

- stringified JSON with highlights definition

Type
  string