
Product
Redesigned Repositories Page: A Faster Way to Prioritize Security Risk
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
text-annotator
Advanced tools
A JavaScript library for annotating plain text in the HTML
The annotation process is:
npm install --save text-annotator-v2
import TextAnnotator from 'text-annotator-v2'
<script src="public/js/text-annotator.min.js"></script>
/*
below is the HTML
<div id="content"><p><i>JavaScript</i> is the <b>world's most popular programming language</b>.</p><p><i>JavaScript</i> is the programming language of the Web. JavaScript is easy to learn.</p></div>
*/
// create an instance of TextAnnotator by passing the html to be annotated
var annotator = new TextAnnotator(document.getElementById('content').innerHTML)
// search for text "JavaScript is the world's most popular programming language.JavaScript is the programming language of the Web." within the HTML
var annotationIndex = annotator.search('JavaScript is the world\'s most popular programming language.JavaScript is the programming language of the Web.')
// annotate the text if finding it
if (annotationIndex !== -1) {
document.getElementById('content').innerHTML = annotator.annotate(annotationIndex)
}
// search for all occurances of "JavaScript" in the HTML
var annotationIndexes = annotator.searchAll('JavaScript')
// annotate all the found occurances of 'Javascript' given their indexes
if (annotationIndexes.length) {
document.getElementById('content').innerHTML = annotator.annotateAll(annotationIndexes)
}
// unannotate all the previously annotated text
document.getElementById('content').innerHTML = annotator.unannotate(annotationIndex)
document.getElementById('content').innerHTML = annotator.unannotateAll(annotationIndexes)
Prop | Type | Description |
---|---|---|
html | string | The HTML string within which a piece of text can be annotated. |
Prop | Type | Description |
---|---|---|
trim | boolean | Whether to trim the piece of text to be annotated. Default is true. |
caseSensitive | boolean | Whether to consider case in search. Default is false. |
prefix | string | A string BEFORE the piece of text to be annotated. Default is ''. |
postfix | string | A string AFTER the piece of text to be annotated. Default is ''. |
Prop | Type | Description |
---|---|---|
tagName | string | The tag name of the annotation tag. Default is span so that the tag is <span ...>. |
baseClassName | string | The base class name of the annotation tag. Default is annotation so that the tag is <span class="annotation" ...>. |
classPattern | string | The pattern of the class used as the ID of the annotation. Default is annotation- so that the tag is <span class="annotation-[annotation]" ...>. |
TBC
FAQs
A JavaScript library for locating and annotating plain text in HTML
The npm package text-annotator receives a total of 728 weekly downloads. As such, text-annotator popularity was classified as not popular.
We found that text-annotator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
Security News
Slopsquatting is a new supply chain threat where AI-assisted code generators recommend hallucinated packages that attackers register and weaponize.
Security News
Multiple deserialization flaws in PyTorch Lightning could allow remote code execution when loading untrusted model files, affecting versions up to 2.4.0.