From 65f30a977ce05f0d2ba88bfbbc4c9b5d8996f5d2 Mon Sep 17 00:00:00 2001 From: Blaise Date: Fri, 28 Oct 2022 15:18:53 -0500 Subject: Set class for styling outside of script --- microlight.js | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/microlight.js b/microlight.js index 917b593..65a9401 100644 --- a/microlight.js +++ b/microlight.js @@ -23,12 +23,6 @@ _document = document, appendChild = 'appendChild', test = 'test', - // style and color templates - textShadow = ';text-shadow:', - opacity = 'opacity:.', - _0px_0px = ' 0px 0px ', - _3px_0px_5 = '3px 0px 5', - brace = ')', i, microlighted, @@ -68,14 +62,7 @@ lastTokenType, // flag determining if token is multi-character multichar, - node, - - // calculating the colors for the style templates - colorArr = /(\d*\, \d*\, \d*)(, ([.\d]*))?/g.exec( - _window.getComputedStyle(el).color - ), - pxColor = 'px rgba('+colorArr[1]+',', - alpha = colorArr[3]||1; + node; // running through characters and highlighting while (prev2 = prev1, @@ -120,26 +107,7 @@ // (some types are highlighted similarly) el[appendChild]( node = _document.createElement('span') - ).setAttribute('style', [ - // 0: not formatted - '', - // 1: keywords - textShadow + _0px_0px+9+pxColor + alpha * .7 + '),' + - _0px_0px+2+pxColor + alpha * .4 + brace, - // 2: punctuation - opacity + 6 + - textShadow + _0px_0px+7+pxColor + alpha / 4 + '),' + - _0px_0px+3+pxColor + alpha / 4 + brace, - // 3: strings and regexps - opacity + 7 + - textShadow + _3px_0px_5+pxColor + alpha / 5 + '),-' + - _3px_0px_5+pxColor + alpha / 5 + brace, - // 4: comments - 'font-style:italic;'+ - opacity + 5 + - textShadow + _3px_0px_5+pxColor + alpha / 4 + '),-' + - _3px_0px_5+pxColor + alpha / 4 + brace - ][ + ).setAttribute('class', 'c'+( // not formatted !tokenType ? 0 : // punctuation @@ -151,7 +119,7 @@ // 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) - ]); + )); node[appendChild](_document.createTextNode(token)); } -- cgit v1.2.3