1
0
Fork 0
forked from 0x2620/oxjs

updates for html parsing, request handling, and editable elements

This commit is contained in:
rlx 2011-10-27 18:50:23 +00:00
commit 62f8a907ea
6 changed files with 153 additions and 69 deletions

View file

@ -288,11 +288,31 @@
'äbçdê'
> Ox.decodeHTML('äbçdê')
'äbçdê'
> Ox.decodeHTML('<b>bold</b>')
'<b>bold</b>'
@*/
Ox.decodeHTML = function(str) {
// relies on dom, but shorter than using this:
// http://www.w3.org/TR/html5/named-character-references.html
return Ox.element('<div>').html(str)[0].childNodes[0].nodeValue;
return Ox.decodeHTMLEntities(Ox.element('<div>').html(str).html());
};
Ox.encodeHTMLEntities = function(str) {
return str.replace(
new RegExp('(' + Object.keys(Ox.HTML_ENTITIES).join('|') + ')', 'g'),
function(match) {
return Ox.HTML_ENTITIES[match];
}
);
};
Ox.decodeHTMLEntities = function(str) {
return str.replace(
new RegExp('(' + Ox.values(Ox.HTML_ENTITIES).join('|') + ')', 'g'),
function(match) {
return Ox.keyOf(Ox.HTML_ENTITIES, match);
}
);
};
/*@