Getting started
You can download the package using npm by running:
$ npm install advanced-mark.js --save-dev
A dist
directory contains files:
JavaScript
mark.js
mark.min.js
mark.es6.js
mark.es6.min.js
jQuery
jquery.mark.js
jquery.mark.min.js
jquery.mark.es6.js
jquery.mark.es6.min.js
node.jquery.mark.es6.js
for use in Virtual DOMs (contains necessaryimport $ from 'jquery'
declaration)
TypeScript declaration files
mark.d.js
mark.es6.d.js
jquery.mark.es6.d.js
node.jquery.mark.es6.d.js
HTML
To include library in web page just add:
<script src="path/to/mark.js"></script>
Note:the library requires UTF-8 encoding and may needs adding charset
attribute:
<script src="path/to/mark.min.js" charset="utf-8"></script>
API
There are four API methods:
- mark() - to highlight custom terms
- markRegExp() - to highlight custom regular expressions
- markRanges() - to highlight ranges with a start and length properties (of text or lines with
markLines
option) - unmark() - to remove highlights
JavaScript
API methods called on an instance object. To initialize a new instance, you have to use:
var instance = new Mark(context);
instance.mark('lorem');
where context
can be:
- a single element get by e.g.
document.getElementById()
ordocument.querySelector()
- a NodeList get by e.g.
document.querySelectorAll()
- an array containing multiple single elements (Note that internally the array is sorted by the element position in the document)
- a string selector (internally calls
document.querySelectorAll()
)
jQuery
API methods called on every jQuery element:
$("div.test").mark('lorem');