MCPcopy Create free account
hub / github.com/hoothin/UserScripts / decodeEntities

Function decodeEntities

Picviewer CE+/dist.user.js:12816–12829  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

12814 nbsp: '\u00A0'
12815 };
12816 function decodeEntities(text){
12817 return text.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, function(_, code){
12818 if (code[0] === '#') {
12819 const isHex = code[1] === 'x' || code[1] === 'X';
12820 const num = parseInt(code.slice(isHex ? 2 : 1), isHex ? 16 : 10);
12821 if (!isNaN(num)) {
12822 try { return String.fromCodePoint(num); } catch(e) {}
12823 }
12824 return '&' + code + ';';
12825 }
12826 const key = code.toLowerCase();
12827 return (key in HTML_ENTITIES) ? HTML_ENTITIES[key] : '&' + code + ';';
12828 });
12829 }
12830 function parseHTMLToFragment(html, fragment, doc){
12831 const stack = [fragment];
12832 const tokenRe = /<!--[\s\S]*?-->|<!doctype[^>]*>|<\/?[a-zA-Z][^>]*>|[^<]+/gi;

Callers 1

parseHTMLToFragmentFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected