evt-text-annotations
v1.0.8
Published
EVT - Text Annotator ================= [![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) [![NPM Package](https://img.shields.io/npm/v/evt-text-annotator.svg)](https://www.npmjs.com/package/evt-text-annot
Downloads
5
Readme
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)
.
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.
getAnnotation(anno)
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
.
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