+ Web Highlighter
+ Background
+ It's from an idea: highlight texts on the website and save the highlighted areas just like what you do in PDF.
+ If you have ever visited medium.com, you must know the feature of highlighting notes: users select a text segment and click the 'highlight' button. Then the text will be highlighted with a shining background color. Besides, the highlighted areas will be saved and recovered when you visit it next time. It's like the simple demo bellow.
+ 
+ This is a useful feature for readers.If you're a developer, you may want your website support it and attract more visits.If you're a user (like me), you may want a browser-plugin to do this.
+ For this reason, the repo (web-highlighter) aims to help you implement highlighting-note on any website quickly (e.g. blogs, document viewers, online books and so on). It contains the core abilities for note highlighting and persistence. And you can implement your own product by some easy-to-use APIs. It has been used for our sites in production.
+
diff --git a/test/fixtures/source.json b/test/fixtures/source.json
new file mode 100644
index 0000000..0bc52d0
--- /dev/null
+++ b/test/fixtures/source.json
@@ -0,0 +1,47 @@
+[
+ {
+ "startMeta": {
+ "parentTagName": "P",
+ "parentIndex": 0,
+ "textOffset": 0
+ },
+ "endMeta": {
+ "parentTagName": "P",
+ "parentIndex": 0,
+ "textOffset": 17
+ },
+ "text": "It's from an idea",
+ "id": "cbfcf177-4a0e-4deb-9f00-66e247ee5363",
+ "__isHighlightSource": {}
+ },
+ {
+ "startMeta": {
+ "parentTagName": "P",
+ "parentIndex": 0,
+ "textOffset": 10
+ },
+ "endMeta": {
+ "parentTagName": "P",
+ "parentIndex": 0,
+ "textOffset": 34
+ },
+ "text": "an idea: highlight texts",
+ "id": "69a33f5e-60f5-4b5d-9f9c-18151a24bf95",
+ "__isHighlightSource": {}
+ },
+ {
+ "startMeta": {
+ "parentTagName": "P",
+ "parentIndex": 0,
+ "textOffset": 8
+ },
+ "endMeta": {
+ "parentTagName": "P",
+ "parentIndex": 0,
+ "textOffset": 26
+ },
+ "text": "m an idea: highlig",
+ "id": "14206065-205f-4c6d-8f80-1e022a6695a3",
+ "__isHighlightSource": {}
+ }
+]
\ No newline at end of file
diff --git a/test/hook.spec.ts b/test/hook.spec.ts
new file mode 100644
index 0000000..5ab1d17
--- /dev/null
+++ b/test/hook.spec.ts
@@ -0,0 +1,200 @@
+import { expect } from 'chai';
+import { readFileSync } from 'fs';
+import { resolve } from 'path';
+import jsdomGlobal from 'jsdom-global';
+import Highlighter from '../src/index';
+import sinon from 'sinon';
+import sources from './fixtures/source.json';
+
+describe('Highlighter Hooks', function () {
+ this.timeout(50000);
+
+ let highlighter: Highlighter;
+ let cleanup;
+
+ beforeEach(() => {
+ const html = readFileSync(resolve(__dirname, 'fixtures', 'index.html'), 'utf-8');
+ cleanup = jsdomGlobal();
+ document.body.innerHTML = html;
+ highlighter = new Highlighter();
+ });
+
+ describe('#Render.UUID', () => {
+ let listener: sinon.SinonSpy