W3C Web Annotation implementation for creating, parsing, and serializing Web Annotations in JSON-LD, with support for HTML+RDFa embedding and DOM-based annotation application.
npm install @dokieli/web-annotation
or
yarn install @dokieli/web-annotation
import { createAnnotation, serializeAnnotationToJSONLD, serializeAnnotationToHTML } from '@dokieli/web-annotation';
const annotation = createAnnotation({
motivatedBy: 'oa:commenting',
body: { value: 'A note.' },
target: { source: 'https://example.org/', selector: { type: 'TextQuoteSelector', exact: 'annotated text' } }
});
const jsonld = serializeAnnotationToJSONLD(annotation);
const html = serializeAnnotationToHTML(annotation);
See API Reference and Examples.
The data in JSON-LD this library emits conforms to the W3C Web Annotation Data Model, validated against the official w3c/web-annotation-tests suite (its MUST assertions). Run the checks with yarn test:conformance.
See the Contributing Guide for development setup, tests, and commit conventions.
Help the project grow by sponsoring it on Open Collective or reach out to us.