This library was created to provide Digital Scholarly Editions users, and specifically EVT-based DSEs, with an easy way to add their own annotations to the edition texts. It is based on the standard W3C - Web Annotation Data Model and it has been developed using the following libraries:
- https://github.com/openannotation/xpath-range
- https://github.com/tilgovi/dom-anchor-text-quote
- https://github.com/tilgovi/dom-anchor-text-position
Installation is performed via npm, use this command: npm install evt-text-annotator
The library exposes two APIs: createAnnotation
and getAnnotation
.
This API takes three values as input: (root, range, note)
.
-
root
identifies the HTML element generated by the text selection made by the user. -
range
identifies the range that is generated when the user selects the text. -
note
identifies the note that the user wants to insert within the selection. Thereturn
of this API is anObject
conform to W3C - Web Annotation Data Model containing the text of the note.
This API takes only one value (anno
) as input.
-
anno
identifies the object that is generated using thecreateAnnotation
API. Thereturn
of this API is aRange
.
A simple example of use of the library:
import {annotator} from "evt-text-annotator";
const range = selection.getRangeAt(0); // Range
const root = range.commonAncestorContainer.parentElement; // HTMLElement
const note = "my note" // input String
// create annotation from text selection
const anno = annotator.createAnnotation(root, range, note); // Annotation
// get a Range form an annotation
const range_anno = annotator.getAnnotation(anno); // Range