diff --git a/microlight.js b/microlight.js index 5aa193a..24e3aab 100644 --- a/microlight.js +++ b/microlight.js @@ -36,9 +36,12 @@ - var reset = function(cls) { + var reset = function(cls = 'microlight', cwords = []) { // nodes to highlight - microlighted = _document.getElementsByClassName(cls||'microlight'); + microlighted = !cls || typeof cls === 'string' ? + _document.getElementsByClassName(cls) : + cls.selector ? _document.querySelectorAll(cls.selector) : + typeof cls[Symbol.iterator] === 'function' ? cls : [cls]; for (i = 0; el = microlighted[i++];) { var text = el.textContent, @@ -148,6 +151,8 @@ tokenType > 6 ? 4 : // regex and strings tokenType > 3 ? 3 : + // is a custom word + cwords.includes(token) ? 1 : // otherwise tokenType == 3, (key)word // (1 if regexp matches, 0 otherwise) + /^(a(bstract|lias|nd|rguments|rray|s(m|sert)?|uto)|b(ase|egin|ool(ean)?|reak|yte)|c(ase|atch|har|hecked|lass|lone|ompl|onst|ontinue)|de(bugger|cimal|clare|f(ault|er)?|init|l(egate|ete)?)|do|double|e(cho|ls?if|lse(if)?|nd|nsure|num|vent|x(cept|ec|p(licit|ort)|te(nds|nsion|rn)))|f(allthrough|alse|inal(ly)?|ixed|loat|or(each)?|riend|rom|unc(tion)?)|global|goto|guard|i(f|mp(lements|licit|ort)|n(it|clude(_once)?|line|out|stanceof|t(erface|ernal)?)?|s)|l(ambda|et|ock|ong)|m(icrolight|odule|utable)|NaN|n(amespace|ative|ext|ew|il|ot|ull)|o(bject|perator|r|ut|verride)|p(ackage|arams|rivate|rotected|rotocol|ublic)|r(aise|e(adonly|do|f|gister|peat|quire(_once)?|scue|strict|try|turn))|s(byte|ealed|elf|hort|igned|izeof|tatic|tring|truct|ubscript|uper|ynchronized|witch)|t(emplate|hen|his|hrows?|ransient|rue|ry|ype(alias|def|id|name|of))|u(n(checked|def(ined)?|ion|less|signed|til)|se|sing)|v(ar|irtual|oid|olatile)|w(char_t|hen|here|hile|ith)|xor|yield)$/[test](token)