text-annotator-v2
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "text-annotator-v2", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A JavaScript library for locating and annotating plain text in HTML", | ||
@@ -5,0 +5,0 @@ "main": "build/text-annotator-v2.js", |
@@ -144,3 +144,2 @@ import TextAnnotator from '../src/text-annotator-v2' | ||
textAnnotator.unannotateAll([0, 1]) | ||
console.log(textAnnotator.html) | ||
const annotatedHtml = textAnnotator.annotate(0) | ||
@@ -155,3 +154,3 @@ expect(annotatedHtml).toBe( | ||
const annotatedHtml = textAnnotator.annotate( | ||
textAnnotator.search('Zhan Huang') | ||
textAnnotator.search(' zhan huang ') | ||
) | ||
@@ -162,1 +161,60 @@ expect(annotatedHtml).toBe( | ||
}) | ||
test('do not trim the search terms', () => { | ||
const textAnnotator = new TextAnnotator('I am Zhan Huang') | ||
const annotationIndex = textAnnotator.search(' zhan huang ', { trim: false }) | ||
expect(annotationIndex).toBe(-1) | ||
}) | ||
test('make the search case sensitive', () => { | ||
const textAnnotator = new TextAnnotator('I am Zhan Huang') | ||
const annotationIndex = textAnnotator.search('zhan huang', { | ||
caseSensitive: true, | ||
}) | ||
expect(annotationIndex).toBe(-1) | ||
}) | ||
test('add prefix and postfix of the search terms', () => { | ||
const textAnnotator = new TextAnnotator('I am Zhan Huang') | ||
const annotationIndex = textAnnotator.search('zhan huang', { | ||
prefix: 'am ', | ||
postfix: '.', | ||
}) | ||
expect(annotationIndex).toBe(-1) | ||
}) | ||
test('annotate using mark tags', () => { | ||
const textAnnotator = new TextAnnotator('I am Zhan Huang') | ||
const annotatedHtml = textAnnotator.annotate( | ||
textAnnotator.search('zhan huang'), | ||
{ tagName: 'mark' } | ||
) | ||
expect(annotatedHtml).toBe( | ||
'I am <mark class="annotation annotation-0">Zhan Huang</mark>' | ||
) | ||
}) | ||
test('annotate using a different base class name', () => { | ||
const textAnnotator = new TextAnnotator('I am Zhan Huang') | ||
const annotatedHtml = textAnnotator.annotate( | ||
textAnnotator.search('zhan huang'), | ||
{ baseClassName: 'highlight' } | ||
) | ||
expect(annotatedHtml).toBe( | ||
'I am <span class="highlight annotation-0">Zhan Huang</span>' | ||
) | ||
}) | ||
test('annotate using a different class pattern', () => { | ||
const textAnnotator = new TextAnnotator('I am Zhan Huang') | ||
const annotatedHtml = textAnnotator.annotate( | ||
textAnnotator.search('zhan huang'), | ||
{ classPattern: 'highlight-' } | ||
) | ||
expect(annotatedHtml).toBe( | ||
'I am <span class="annotation highlight-0">Zhan Huang</span>' | ||
) | ||
}) |
40492
693