forked from 0x2620/oxjs
updates for html parsing, request handling, and editable elements
This commit is contained in:
parent
a949ad2cf4
commit
62f8a907ea
6 changed files with 153 additions and 69 deletions
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
|
|||
|
|
@ -37,15 +37,22 @@ Ox.parseHTML <f> Takes HTML from an untrusted source and returns something sane
|
|||
|
||||
Ox.parseHTML = (function() {
|
||||
var defaultTags = [
|
||||
'a', 'b', 'blockquote', 'br', 'cite', 'code',
|
||||
'del', 'em', 'i', 'img', 'ins',
|
||||
'li', 'ol', 'p', 'q', 'rtl',
|
||||
's', 'strong', 'sub', 'sup',
|
||||
'table', 'tbody', 'td', 'th', 'tr', 'ul', '[]'
|
||||
// inline formatting
|
||||
'b', 'code', 'i', 'q', 's', 'sub', 'sup', 'u',
|
||||
// block
|
||||
'blockquote', 'h1', 'p', 'pre',
|
||||
// lists
|
||||
'li', 'ol', 'ul',
|
||||
// tables
|
||||
'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr',
|
||||
// other
|
||||
'a', 'br', 'img',
|
||||
// special
|
||||
'rtl', '[]'
|
||||
],
|
||||
parse = {
|
||||
a: {
|
||||
'<a [^<>]*?href="(https?:\/\/.+?)".*?>': '<a href="{1}" title="{1}">',
|
||||
'<a [^<>]*?href="((https?:\/\/|\/).+?)".*?>': '<a href="{1}" title="{1}">',
|
||||
'<\/a>': '</a>'
|
||||
},
|
||||
img: {
|
||||
|
|
@ -90,7 +97,7 @@ Ox.parseHTML = (function() {
|
|||
html = html.replace(new RegExp(tab + i + tab, 'gi'), match);
|
||||
});
|
||||
//html = html.replace(/\n/g, '<br/>\n');
|
||||
html = html.replace(/\n/g, '<br/>');
|
||||
html = html.replace(/\n\n/g, '<br/><br/>');
|
||||
// close extra opening (and remove extra closing) tags
|
||||
// note: this converts '"' to '"'
|
||||
return Ox.element('<div>').html(html).html();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,21 @@ Ox.extend = function() {
|
|||
return obj;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.keyOf <f> undocumented
|
||||
@*/
|
||||
|
||||
Ox.keyOf = function(obj, val) {
|
||||
var key;
|
||||
Ox.forEach(obj, function(v, k) {
|
||||
if (v == val) {
|
||||
key = k;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return key;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.serialize <f> Parses an object into query parameters
|
||||
> Ox.serialize({a: 1, b: 2, c: 3})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue