text-highlighter
v1.0.2
Published
Highlight text in DOM.
Downloads
80
Readme
text-highlighter
Highlight text in DOM.
Installation
$ npm install text-highlighter --save
Usage
<div id="container">
We 💓 TypeScript!
</div>
<script src="lib/text-highlighter.js"></script>
<script>
var textHighlighter = new TextHighlighter(document.getElementById('container'));
// apply highlight
textHighlighter.highlight('typescript');
// remove highlight
textHighlighter.dehighlight();
</script>
Support Zenkaku & Hankaku
before
<div id="container">
We 💓 TypeScript!
</div>
<script>
...
// apply highlight
textHighlighter.highlight('typescript');
</script>
after
<div id="container">
We 💓 <mark>TypeScript</mark>!
</div>
Thanks
- http://stackoverflow.com/questions/10416643/highlight-words-in-html-using-regex-javascript-almost-there
- http://jquery.nj-clucker.com/change-double-byte-to-half-width/
License
MIT