From 64ffbe66078256b625e5bf71b084b2056ca5c528 Mon Sep 17 00:00:00 2001 From: Felippe Regazio Date: Sat, 5 Jun 2021 02:11:00 -0300 Subject: [PATCH 1/2] extended the reset() function target mode (class string, target, element or element list) --- microlight.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/microlight.js b/microlight.js index 5aa193a..98e4a25 100644 --- a/microlight.js +++ b/microlight.js @@ -36,9 +36,12 @@ - var reset = function(cls) { + var reset = function(cls = 'microlight') { // 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, From d5d2db4f72a9e93b4996aeccd5592fb7b31ed693 Mon Sep 17 00:00:00 2001 From: Felippe Regazio Date: Sat, 5 Jun 2021 02:11:43 -0300 Subject: [PATCH 2/2] added custom word list to specify new words to highlight --- microlight.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microlight.js b/microlight.js index 98e4a25..24e3aab 100644 --- a/microlight.js +++ b/microlight.js @@ -36,7 +36,7 @@ - var reset = function(cls = 'microlight') { + var reset = function(cls = 'microlight', cwords = []) { // nodes to highlight microlighted = !cls || typeof cls === 'string' ? _document.getElementsByClassName(cls) : @@ -151,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)