JavaScript functions to encode HTML5 markup-significant characters and to decode HTML5 character references
//encode HTML markup-significant characters
// keepCharacterReferences: if true, the ampersands of HTML5 character references will not be encoded
function encodeHTML(str, keepCharacterReferences){
"use strict";
var namedChars, rxp;
if(keepCharacterReferences){
//see http://www.w3.org/TR/html5/syntax.html#named-character-references
//this list excludes: AMP amp LT lt GT gt QUOT quot apos
namedChars = "Aacute|aacute|Abreve|abreve|ac|acd|acE|Acirc|acirc|acute|Acy|acy|AElig|aelig|af|Afr|afr|Agrave|agrave|alefsym|aleph|Alpha|alpha|Amacr|amacr|amalg|And|and|andand|andd|andslope|andv|ang|ange|angle|angmsd|angmsdaa|angmsdab|angmsdac|angmsdad|angmsdae|angmsdaf|angmsdag|angmsdah|angrt|angrtvb|angrtvbd|angsph|angst|angzarr|Aogon|aogon|Aopf|aopf|ap|apacir|apE|ape|apid|ApplyFunction|approx|approxeq|Aring|aring|Ascr|ascr|Assign|ast|asymp|asympeq|Atilde|atilde|Auml|auml|awconint|awint|backcong|backepsilon|backprime|backsim|backsimeq|Backslash|Barv|barvee|Barwed|barwed|barwedge|bbrk|bbrktbrk|bcong|Bcy|bcy|bdquo|becaus|Because|because|bemptyv|bepsi|bernou|Bernoullis|Beta|beta|beth|between|Bfr|bfr|bigcap|bigcirc|bigcup|bigodot|bigoplus|bigotimes|bigsqcup|bigstar|bigtriangledown|bigtriangleup|biguplus|bigvee|bigwedge|bkarow|blacklozenge|blacksquare|blacktriangle|blacktriangledown|blacktriangleleft|blacktriangleright|blank|blk12|blk14|blk34|block|bne|bnequiv|bNot|bnot|Bopf|bopf|bot|bottom|bowtie|boxbox|boxDL|boxDl|boxdL|boxdl|boxDR|boxDr|boxdR|boxdr|boxH|boxh|boxHD|boxHd|boxhD|boxhd|boxHU|boxHu|boxhU|boxhu|boxminus|boxplus|boxtimes|boxUL|boxUl|boxuL|boxul|boxUR|boxUr|boxuR|boxur|boxV|boxv|boxVH|boxVh|boxvH|boxvh|boxVL|boxVl|boxvL|boxvl|boxVR|boxVr|boxvR|boxvr|bprime|Breve|breve|brvbar|Bscr|bscr|bsemi|bsim|bsime|bsol|bsolb|bsolhsub|bull|bullet|bump|bumpE|bumpe|Bumpeq|bumpeq|Cacute|cacute|Cap|cap|capand|capbrcup|capcap|capcup|capdot|CapitalDifferentialD|caps|caret|caron|Cayleys|ccaps|Ccaron|ccaron|Ccedil|ccedil|Ccirc|ccirc|Cconint|ccups|ccupssm|Cdot|cdot|cedil|Cedilla|cemptyv|cent|CenterDot|centerdot|Cfr|cfr|CHcy|chcy|check|checkmark|Chi|chi|cir|circ|circeq|circlearrowleft|circlearrowright|circledast|circledcirc|circleddash|CircleDot|circledR|circledS|CircleMinus|CirclePlus|CircleTimes|cirE|cire|cirfnint|cirmid|cirscir|ClockwiseContourIntegral|CloseCurlyDoubleQuote|CloseCurlyQuote|clubs|clubsuit|Colon|colon|Colone|colone|coloneq|comma|commat|comp|compfn|complement|complexes|cong|congdot|Congruent|Conint|conint|ContourIntegral|Copf|copf|coprod|Coproduct|COPY|copy|copysr|CounterClockwiseContourIntegral|crarr|Cross|cross|Cscr|cscr|csub|csube|csup|csupe|ctdot|cudarrl|cudarrr|cuepr|cuesc|cularr|cularrp|Cup|cup|cupbrcap|CupCap|cupcap|cupcup|cupdot|cupor|cups|curarr|curarrm|curlyeqprec|curlyeqsucc|curlyvee|curlywedge|curren|curvearrowleft|curvearrowright|cuvee|cuwed|cwconint|cwint|cylcty|Dagger|dagger|daleth|Darr|dArr|darr|dash|Dashv|dashv|dbkarow|dblac|Dcaron|dcaron|Dcy|dcy|DD|dd|ddagger|ddarr|DDotrahd|ddotseq|deg|Del|Delta|delta|demptyv|dfisht|Dfr|dfr|dHar|dharl|dharr|DiacriticalAcute|DiacriticalDot|DiacriticalDoubleAcute|DiacriticalGrave|DiacriticalTilde|diam|Diamond|diamond|diamondsuit|diams|die|DifferentialD|digamma|disin|div|divide|divideontimes|divonx|DJcy|djcy|dlcorn|dlcrop|dollar|Dopf|dopf|Dot|dot|DotDot|doteq|doteqdot|DotEqual|dotminus|dotplus|dotsquare|doublebarwedge|DoubleContourIntegral|DoubleDot|DoubleDownArrow|DoubleLeftArrow|DoubleLeftRightArrow|DoubleLeftTee|DoubleLongLeftArrow|DoubleLongLeftRightArrow|DoubleLongRightArrow|DoubleRightArrow|DoubleRightTee|DoubleUpArrow|DoubleUpDownArrow|DoubleVerticalBar|DownArrow|Downarrow|downarrow|DownArrowBar|DownArrowUpArrow|DownBreve|downdownarrows|downharpoonleft|downharpoonright|DownLeftRightVector|DownLeftTeeVector|DownLeftVector|DownLeftVectorBar|DownRightTeeVector|DownRightVector|DownRightVectorBar|DownTee|DownTeeArrow|drbkarow|drcorn|drcrop|Dscr|dscr|DScy|dscy|dsol|Dstrok|dstrok|dtdot|dtri|dtrif|duarr|duhar|dwangle|DZcy|dzcy|dzigrarr|Eacute|eacute|easter|Ecaron|ecaron|ecir|Ecirc|ecirc|ecolon|Ecy|ecy|eDDot|Edot|eDot|edot|ee|efDot|Efr|efr|eg|Egrave|egrave|egs|egsdot|el|Element|elinters|ell|els|elsdot|Emacr|emacr|empty|emptyset|EmptySmallSquare|emptyv|EmptyVerySmallSquare|emsp|emsp13|emsp14|ENG|eng|ensp|Eogon|eogon|Eopf|eopf|epar|eparsl|eplus|epsi|Epsilon|epsilon|epsiv|eqcirc|eqcolon|eqsim|eqslantgtr|eqslantless|Equal|equals|EqualTilde|equest|Equilibrium|equiv|equivDD|eqvparsl|erarr|erDot|Escr|escr|esdot|Esim|esim|Eta|eta|ETH|eth|Euml|euml|euro|excl|exist|Exists|expectation|ExponentialE|exponentiale|fallingdotseq|Fcy|fcy|female|ffilig|fflig|ffllig|Ffr|ffr|filig|FilledSmallSquare|FilledVerySmallSquare|fjlig|flat|fllig|fltns|fnof|Fopf|fopf|ForAll|forall|fork|forkv|Fouriertrf|fpartint|frac12|frac13|frac14|frac15|frac16|frac18|frac23|frac25|frac34|frac35|frac38|frac45|frac56|frac58|frac78|frasl|frown|Fscr|fscr|gacute|Gamma|gamma|Gammad|gammad|gap|Gbreve|gbreve|Gcedil|Gcirc|gcirc|Gcy|gcy|Gdot|gdot|gE|ge|gEl|gel|geq|geqq|geqslant|ges|gescc|gesdot|gesdoto|gesdotol|gesl|gesles|Gfr|gfr|Gg|gg|ggg|gimel|GJcy|gjcy|gl|gla|glE|glj|gnap|gnapprox|gnE|gne|gneq|gneqq|gnsim|Gopf|gopf|grave|GreaterEqual|GreaterEqualLess|GreaterFullEqual|GreaterGreater|GreaterLess|GreaterSlantEqual|GreaterTilde|Gscr|gscr|gsim|gsime|gsiml|Gt|gtcc|gtcir|gtdot|gtlPar|gtquest|gtrapprox|gtrarr|gtrdot|gtreqless|gtreqqless|gtrless|gtrsim|gvertneqq|gvnE|Hacek|hairsp|half|hamilt|HARDcy|hardcy|hArr|harr|harrcir|harrw|Hat|hbar|Hcirc|hcirc|hearts|heartsuit|hellip|hercon|Hfr|hfr|HilbertSpace|hksearow|hkswarow|hoarr|homtht|hookleftarrow|hookrightarrow|Hopf|hopf|horbar|HorizontalLine|Hscr|hscr|hslash|Hstrok|hstrok|HumpDownHump|HumpEqual|hybull|hyphen|Iacute|iacute|ic|Icirc|icirc|Icy|icy|Idot|IEcy|iecy|iexcl|iff|Ifr|ifr|Igrave|igrave|ii|iiiint|iiint|iinfin|iiota|IJlig|ijlig|Im|Imacr|imacr|image|ImaginaryI|imagline|imagpart|imath|imof|imped|Implies|in|incare|infin|infintie|inodot|Int|int|intcal|integers|Integral|intercal|Intersection|intlarhk|intprod|InvisibleComma|InvisibleTimes|IOcy|iocy|Iogon|iogon|Iopf|iopf|Iota|iota|iprod|iquest|Iscr|iscr|isin|isindot|isinE|isins|isinsv|isinv|it|Itilde|itilde|Iukcy|iukcy|Iuml|iuml|Jcirc|jcirc|Jcy|jcy|Jfr|jfr|jmath|Jopf|jopf|Jscr|jscr|Jsercy|jsercy|Jukcy|jukcy|Kappa|kappa|kappav|Kcedil|kcedil|Kcy|kcy|Kfr|kfr|kgreen|KHcy|khcy|KJcy|kjcy|Kopf|kopf|Kscr|kscr|lAarr|Lacute|lacute|laemptyv|lagran|Lambda|lambda|Lang|lang|langd|langle|lap|Laplacetrf|laquo|Larr|lArr|larr|larrb|larrbfs|larrfs|larrhk|larrlp|larrpl|larrsim|larrtl|lat|lAtail|latail|late|lates|lBarr|lbarr|lbbrk|lbrace|lbrack|lbrke|lbrksld|lbrkslu|Lcaron|lcaron|Lcedil|lcedil|lceil|lcub|Lcy|lcy|ldca|ldquo|ldquor|ldrdhar|ldrushar|ldsh|lE|le|LeftAngleBracket|LeftArrow|Leftarrow|leftarrow|LeftArrowBar|LeftArrowRightArrow|leftarrowtail|LeftCeiling|LeftDoubleBracket|LeftDownTeeVector|LeftDownVector|LeftDownVectorBar|LeftFloor|leftharpoondown|leftharpoonup|leftleftarrows|LeftRightArrow|Leftrightarrow|leftrightarrow|leftrightarrows|leftrightharpoons|leftrightsquigarrow|LeftRightVector|LeftTee|LeftTeeArrow|LeftTeeVector|leftthreetimes|LeftTriangle|LeftTriangleBar|LeftTriangleEqual|LeftUpDownVector|LeftUpTeeVector|LeftUpVector|LeftUpVectorBar|LeftVector|LeftVectorBar|lEg|leg|leq|leqq|leqslant|les|lescc|lesdot|lesdoto|lesdotor|lesg|lesges|lessapprox|lessdot|lesseqgtr|lesseqqgtr|LessEqualGreater|LessFullEqual|LessGreater|lessgtr|LessLess|lesssim|LessSlantEqual|LessTilde|lfisht|lfloor|Lfr|lfr|lg|lgE|lHar|lhard|lharu|lharul|lhblk|LJcy|ljcy|Ll|ll|llarr|llcorner|Lleftarrow|llhard|lltri|Lmidot|lmidot|lmoust|lmoustache|lnap|lnapprox|lnE|lne|lneq|lneqq|lnsim|loang|loarr|lobrk|LongLeftArrow|Longleftarrow|longleftarrow|LongLeftRightArrow|Longleftrightarrow|longleftrightarrow|longmapsto|LongRightArrow|Longrightarrow|longrightarrow|looparrowleft|looparrowright|lopar|Lopf|lopf|loplus|lotimes|lowast|lowbar|LowerLeftArrow|LowerRightArrow|loz|lozenge|lozf|lpar|lparlt|lrarr|lrcorner|lrhar|lrhard|lrm|lrtri|lsaquo|Lscr|lscr|Lsh|lsh|lsim|lsime|lsimg|lsqb|lsquo|lsquor|Lstrok|lstrok|Lt|ltcc|ltcir|ltdot|lthree|ltimes|ltlarr|ltquest|ltri|ltrie|ltrif|ltrPar|lurdshar|luruhar|lvertneqq|lvnE|macr|male|malt|maltese|Map|map|mapsto|mapstodown|mapstoleft|mapstoup|marker|mcomma|Mcy|mcy|mdash|mDDot|measuredangle|MediumSpace|Mellintrf|Mfr|mfr|mho|micro|mid|midast|midcir|middot|minus|minusb|minusd|minusdu|MinusPlus|mlcp|mldr|mnplus|models|Mopf|mopf|mp|Mscr|mscr|mstpos|Mu|mu|multimap|mumap|nabla|Nacute|nacute|nang|nap|napE|napid|napos|napprox|natur|natural|naturals|nbsp|nbump|nbumpe|ncap|Ncaron|ncaron|Ncedil|ncedil|ncong|ncongdot|ncup|Ncy|ncy|ndash|ne|nearhk|neArr|nearr|nearrow|nedot|NegativeMediumSpace|NegativeThickSpace|NegativeThinSpace|NegativeVeryThinSpace|nequiv|nesear|nesim|NestedGreaterGreater|NestedLessLess|NewLine|nexist|nexists|Nfr|nfr|ngE|nge|ngeq|ngeqq|ngeqslant|nges|nGg|ngsim|nGt|ngt|ngtr|nGtv|nhArr|nharr|nhpar|ni|nis|nisd|niv|NJcy|njcy|nlArr|nlarr|nldr|nlE|nle|nLeftarrow|nleftarrow|nLeftrightarrow|nleftrightarrow|nleq|nleqq|nleqslant|nles|nless|nLl|nlsim|nLt|nlt|nltri|nltrie|nLtv|nmid|NoBreak|NonBreakingSpace|Nopf|nopf|Not|not|NotCongruent|NotCupCap|NotDoubleVerticalBar|NotElement|NotEqual|NotEqualTilde|NotExists|NotGreater|NotGreaterEqual|NotGreaterFullEqual|NotGreaterGreater|NotGreaterLess|NotGreaterSlantEqual|NotGreaterTilde|NotHumpDownHump|NotHumpEqual|notin|notindot|notinE|notinva|notinvb|notinvc|NotLeftTriangle|NotLeftTriangleBar|NotLeftTriangleEqual|NotLess|NotLessEqual|NotLessGreater|NotLessLess|NotLessSlantEqual|NotLessTilde|NotNestedGreaterGreater|NotNestedLessLess|notni|notniva|notnivb|notnivc|NotPrecedes|NotPrecedesEqual|NotPrecedesSlantEqual|NotReverseElement|NotRightTriangle|NotRightTriangleBar|NotRightTriangleEqual|NotSquareSubset|NotSquareSubsetEqual|NotSquareSuperset|NotSquareSupersetEqual|NotSubset|NotSubsetEqual|NotSucceeds|NotSucceedsEqual|NotSucceedsSlantEqual|NotSucceedsTilde|NotSuperset|NotSupersetEqual|NotTilde|NotTildeEqual|NotTildeFullEqual|NotTildeTilde|NotVerticalBar|npar|nparallel|nparsl|npart|npolint|npr|nprcue|npre|nprec|npreceq|nrArr|nrarr|nrarrc|nrarrw|nRightarrow|nrightarrow|nrtri|nrtrie|nsc|nsccue|nsce|Nscr|nscr|nshortmid|nshortparallel|nsim|nsime|nsimeq|nsmid|nspar|nsqsube|nsqsupe|nsub|nsubE|nsube|nsubset|nsubseteq|nsubseteqq|nsucc|nsucceq|nsup|nsupE|nsupe|nsupset|nsupseteq|nsupseteqq|ntgl|Ntilde|ntilde|ntlg|ntriangleleft|ntrianglelefteq|ntriangleright|ntrianglerighteq|Nu|nu|num|numero|numsp|nvap|nVDash|nVdash|nvDash|nvdash|nvge|nvgt|nvHarr|nvinfin|nvlArr|nvle|nvlt|nvltrie|nvrArr|nvrtrie|nvsim|nwarhk|nwArr|nwarr|nwarrow|nwnear|Oacute|oacute|oast|ocir|Ocirc|ocirc|Ocy|ocy|odash|Odblac|odblac|odiv|odot|odsold|OElig|oelig|ofcir|Ofr|ofr|ogon|Ograve|ograve|ogt|ohbar|ohm|oint|olarr|olcir|olcross|oline|olt|Omacr|omacr|Omega|omega|Omicron|omicron|omid|ominus|Oopf|oopf|opar|OpenCurlyDoubleQuote|OpenCurlyQuote|operp|oplus|Or|or|orarr|ord|order|orderof|ordf|ordm|origof|oror|orslope|orv|oS|Oscr|oscr|Oslash|oslash|osol|Otilde|otilde|Otimes|otimes|otimesas|Ouml|ouml|ovbar|OverBar|OverBrace|OverBracket|OverParenthesis|par|para|parallel|parsim|parsl|part|PartialD|Pcy|pcy|percnt|period|permil|perp|pertenk|Pfr|pfr|Phi|phi|phiv|phmmat|phone|Pi|pi|pitchfork|piv|planck|planckh|plankv|plus|plusacir|plusb|pluscir|plusdo|plusdu|pluse|PlusMinus|plusmn|plussim|plustwo|pm|Poincareplane|pointint|Popf|popf|pound|Pr|pr|prap|prcue|prE|pre|prec|precapprox|preccurlyeq|Precedes|PrecedesEqual|PrecedesSlantEqual|PrecedesTilde|preceq|precnapprox|precneqq|precnsim|precsim|Prime|prime|primes|prnap|prnE|prnsim|prod|Product|profalar|profline|profsurf|prop|Proportion|Proportional|propto|prsim|prurel|Pscr|pscr|Psi|psi|puncsp|Qfr|qfr|qint|Qopf|qopf|qprime|Qscr|qscr|quaternions|quatint|quest|questeq|rAarr|race|Racute|racute|radic|raemptyv|Rang|rang|rangd|range|rangle|raquo|Rarr|rArr|rarr|rarrap|rarrb|rarrbfs|rarrc|rarrfs|rarrhk|rarrlp|rarrpl|rarrsim|Rarrtl|rarrtl|rarrw|rAtail|ratail|ratio|rationals|RBarr|rBarr|rbarr|rbbrk|rbrace|rbrack|rbrke|rbrksld|rbrkslu|Rcaron|rcaron|Rcedil|rcedil|rceil|rcub|Rcy|rcy|rdca|rdldhar|rdquo|rdquor|rdsh|Re|real|realine|realpart|reals|rect|REG|reg|ReverseElement|ReverseEquilibrium|ReverseUpEquilibrium|rfisht|rfloor|Rfr|rfr|rHar|rhard|rharu|rharul|Rho|rho|rhov|RightAngleBracket|RightArrow|Rightarrow|rightarrow|RightArrowBar|RightArrowLeftArrow|rightarrowtail|RightCeiling|RightDoubleBracket|RightDownTeeVector|RightDownVector|RightDownVectorBar|RightFloor|rightharpoondown|rightharpoonup|rightleftarrows|rightleftharpoons|rightrightarrows|rightsquigarrow|RightTee|RightTeeArrow|RightTeeVector|rightthreetimes|RightTriangle|RightTriangleBar|RightTriangleEqual|RightUpDownVector|RightUpTeeVector|RightUpVector|RightUpVectorBar|RightVector|RightVectorBar|ring|risingdotseq|rlarr|rlhar|rlm|rmoust|rmoustache|rnmid|roang|roarr|robrk|ropar|Ropf|ropf|roplus|rotimes|RoundImplies|rpar|rpargt|rppolint|rrarr|Rrightarrow|rsaquo|Rscr|rscr|Rsh|rsh|rsqb|rsquo|rsquor|rthree|rtimes|rtri|rtrie|rtrif|rtriltri|RuleDelayed|ruluhar|rx|Sacute|sacute|sbquo|Sc|sc|scap|Scaron|scaron|sccue|scE|sce|Scedil|scedil|Scirc|scirc|scnap|scnE|scnsim|scpolint|scsim|Scy|scy|sdot|sdotb|sdote|searhk|seArr|searr|searrow|sect|semi|seswar|setminus|setmn|sext|Sfr|sfr|sfrown|sharp|SHCHcy|shchcy|SHcy|shcy|ShortDownArrow|ShortLeftArrow|shortmid|shortparallel|ShortRightArrow|ShortUpArrow|shy|Sigma|sigma|sigmaf|sigmav|sim|simdot|sime|simeq|simg|simgE|siml|simlE|simne|simplus|simrarr|slarr|SmallCircle|smallsetminus|smashp|smeparsl|smid|smile|smt|smte|smtes|SOFTcy|softcy|sol|solb|solbar|Sopf|sopf|spades|spadesuit|spar|sqcap|sqcaps|sqcup|sqcups|Sqrt|sqsub|sqsube|sqsubset|sqsubseteq|sqsup|sqsupe|sqsupset|sqsupseteq|squ|Square|square|SquareIntersection|SquareSubset|SquareSubsetEqual|SquareSuperset|SquareSupersetEqual|SquareUnion|squarf|squf|srarr|Sscr|sscr|ssetmn|ssmile|sstarf|Star|star|starf|straightepsilon|straightphi|strns|Sub|sub|subdot|subE|sube|subedot|submult|subnE|subne|subplus|subrarr|Subset|subset|subseteq|subseteqq|SubsetEqual|subsetneq|subsetneqq|subsim|subsub|subsup|succ|succapprox|succcurlyeq|Succeeds|SucceedsEqual|SucceedsSlantEqual|SucceedsTilde|succeq|succnapprox|succneqq|succnsim|succsim|SuchThat|Sum|sum|sung|Sup|sup|sup1|sup2|sup3|supdot|supdsub|supE|supe|supedot|Superset|SupersetEqual|suphsol|suphsub|suplarr|supmult|supnE|supne|supplus|Supset|supset|supseteq|supseteqq|supsetneq|supsetneqq|supsim|supsub|supsup|swarhk|swArr|swarr|swarrow|swnwar|szlig|Tab|target|Tau|tau|tbrk|Tcaron|tcaron|Tcedil|tcedil|Tcy|tcy|tdot|telrec|Tfr|tfr|there4|Therefore|therefore|Theta|theta|thetasym|thetav|thickapprox|thicksim|ThickSpace|thinsp|ThinSpace|thkap|thksim|THORN|thorn|Tilde|tilde|TildeEqual|TildeFullEqual|TildeTilde|times|timesb|timesbar|timesd|tint|toea|top|topbot|topcir|Topf|topf|topfork|tosa|tprime|TRADE|trade|triangle|triangledown|triangleleft|trianglelefteq|triangleq|triangleright|trianglerighteq|tridot|trie|triminus|TripleDot|triplus|trisb|tritime|trpezium|Tscr|tscr|TScy|tscy|TSHcy|tshcy|Tstrok|tstrok|twixt|twoheadleftarrow|twoheadrightarrow|Uacute|uacute|Uarr|uArr|uarr|Uarrocir|Ubrcy|ubrcy|Ubreve|ubreve|Ucirc|ucirc|Ucy|ucy|udarr|Udblac|udblac|udhar|ufisht|Ufr|ufr|Ugrave|ugrave|uHar|uharl|uharr|uhblk|ulcorn|ulcorner|ulcrop|ultri|Umacr|umacr|uml|UnderBar|UnderBrace|UnderBracket|UnderParenthesis|Union|UnionPlus|Uogon|uogon|Uopf|uopf|UpArrow|Uparrow|uparrow|UpArrowBar|UpArrowDownArrow|UpDownArrow|Updownarrow|updownarrow|UpEquilibrium|upharpoonleft|upharpoonright|uplus|UpperLeftArrow|UpperRightArrow|Upsi|upsi|upsih|Upsilon|upsilon|UpTee|UpTeeArrow|upuparrows|urcorn|urcorner|urcrop|Uring|uring|urtri|Uscr|uscr|utdot|Utilde|utilde|utri|utrif|uuarr|Uuml|uuml|uwangle|vangrt|varepsilon|varkappa|varnothing|varphi|varpi|varpropto|vArr|varr|varrho|varsigma|varsubsetneq|varsubsetneqq|varsupsetneq|varsupsetneqq|vartheta|vartriangleleft|vartriangleright|Vbar|vBar|vBarv|Vcy|vcy|VDash|Vdash|vDash|vdash|Vdashl|Vee|vee|veebar|veeeq|vellip|Verbar|verbar|Vert|vert|VerticalBar|VerticalLine|VerticalSeparator|VerticalTilde|VeryThinSpace|Vfr|vfr|vltri|vnsub|vnsup|Vopf|vopf|vprop|vrtri|Vscr|vscr|vsubnE|vsubne|vsupnE|vsupne|Vvdash|vzigzag|Wcirc|wcirc|wedbar|Wedge|wedge|wedgeq|weierp|Wfr|wfr|Wopf|wopf|wp|wr|wreath|Wscr|wscr|xcap|xcirc|xcup|xdtri|Xfr|xfr|xhArr|xharr|Xi|xi|xlArr|xlarr|xmap|xnis|xodot|Xopf|xopf|xoplus|xotime|xrArr|xrarr|Xscr|xscr|xsqcup|xuplus|xutri|xvee|xwedge|Yacute|yacute|YAcy|yacy|Ycirc|ycirc|Ycy|ycy|yen|Yfr|yfr|YIcy|yicy|Yopf|yopf|Yscr|yscr|YUcy|yucy|Yuml|yuml|Zacute|zacute|Zcaron|zcaron|Zcy|zcy|Zdot|zdot|zeetrf|ZeroWidthSpace|Zeta|zeta|Zfr|zfr|ZHcy|zhcy|zigrarr|Zopf|zopf|Zscr|zscr|zwj|zwnj";
rxp = new RegExp("&(?!(?:#([0-9]+|[xX][a-fA-F0-9]+)|"+namedChars+");)", "g"); //only matches ampersands that are not part of a character reference, with exception to those for: & < > " '
}
return str.replace((rxp || /&/g), "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
//decode HTML character references
function decodeHTML(str){
"use strict";
var tmp = document.createElement("div");
tmp.innerHTML = str.replace(/</g, "<").replace(/>/g, ">");
return tmp.firstChild.nodeValue;
}