1.0.8 • Published 2 years ago
evt-text-annotations v1.0.8
EVT - Text Annotator
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
Installation is performed via npm, use this command: npm install evt-text-annotator
API Documentation
The library exposes two APIs: createAnnotation and getAnnotation.
createAnnotation(root, range, note)
This API takes three values as input: (root, range, note).
rootidentifies the HTML element generated by the text selection made by the user. rangeidentifies the range that is generated when the user selects the text. noteidentifies the note that the user wants to insert within the selection. Thereturnof this API is anObjectconform to W3C - Web Annotation Data Model containing the text of the note.
getAnnotation(anno)
This API takes only one value (anno) as input.
annoidentifies the object that is generated using thecreateAnnotationAPI. Thereturnof this API is aRange.
Usage
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