Jag försöker få att webbeditorn HTMLAREA inte ska koda om mina &.nbsp; och har hittat en patch som ska lösa detta, men jag får det inte att fungera, är rädd att det beror på mina usla javascriptkunskaper.
Denna kod försöker jag få in:
--- htmlarea.js.rc3 2005-03-15 12:44:56.664398136 +0000
+++ htmlarea.js 2005-03-15 12:44:22.442600640 +0000
@@ -2346,6 +2346,10 @@
}
}
+HTMLArea.encodeEntities = function(value) {
+ return value.replace(/&/g,'&').replace(/\"/g,'"').replace(/</g,'^lt;').replace(/>/g,'>');
+}
+
HTMLArea.getHTMLWrapper = function(root, outputRoot, editor) {
var html = "";
switch (root.nodeType) {
@@ -2422,7 +2426,7 @@
// here; we don't need them.
continue;
}
- html += " " + name + '="' + value + '"';
+ html += " " + name + '="' + HTMLArea.encodeEntities(value) + '"';
}
if (html != "") {
html += closed ? " />" : ">";
i htmlarea.js nå´n stans här (rad 1947) antar jag, (jag bifogar hela htmlarea.js ifall jag är ute och cyklar)
// performs HTML encoding of some given string
HTMLArea.htmlEncode = function(str) {
// we don't need regexp for that, but.. so be it for now.
str = str.replace(/&/ig, "&");
str = str.replace(/</ig, "<");
str = str.replace(/>/ig, ">");
str = str.replace(/\x22/ig, """);
// \x22 means '"' -- we use hex reprezentation so that we don't disturb
// JS compressors (well, at least mine fails.. ;)
return str;
};
// Retrieves the HTML code from the given node. This is a replacement for
// getting innerHTML, using standard DOM calls.
HTMLArea.getHTML = function(root, outputRoot, editor) {
var html = "";
switch (root.nodeType) {
case 1: // Node.ELEMENT_NODE
case 11: // Node.DOCUMENT_FRAGMENT_NODE
var closed;
var i;
var root_tag = (root.nodeType == 1) ? root.tagName.toLowerCase() : '';
if (HTMLArea.is_ie && root_tag == "head") {
if (outputRoot)
html += "<head>";
// lowercasize
var save_multiline = RegExp.multiline;
RegExp.multiline = true;
var txt = root.innerHTML.replace(HTMLArea.RE_tagName, function(str, p1, p2) {
return p1 + p2.toLowerCase();
});
RegExp.multiline = save_multiline;
html += txt;
if (outputRoot)
html += "</head>";
break;
} else if (outputRoot) {
closed = (!(root.hasChildNodes() || HTMLArea.needsClosingTag(root)));
html = "<" + root.tagName.toLowerCase();
var attrs = root.attributes;
for (i = 0; i < attrs.length; ++i) {
var a = attrs.item(i);
if (!a.specified && attrs.item(i).nodeName.toLowerCase().indexOf("shape") == -1 && attrs.item(i).nodeName.toLowerCase().indexOf("coords") == -1) {
continue;
}
var name = a.nodeName.toLowerCase();
if (/_moz|contenteditable|_msh/.test(name)) {
// avoid certain attributes
continue;
}
var value;
if (name != "style") {
// IE5.5 reports 25 when cellSpacing is
// 1; other values might be doomed too.
// For this reason we extract the
// values directly from the root node.
// I'm starting to HATE JavaScript
// development. Browser differences
// suck.
//
// Using Gecko the values of href and src are converted to absolute links
// unless we get them using nodeValue()
if (typeof root[a.nodeName] != "undefined" && name != "href" && name != "src") {
value = root[a.nodeName];
} else {
value = a.nodeValue;
// IE seems not willing to return the original values - it converts to absolute
// links using a.nodeValue, a.value, a.stringValue, root.getAttribute("href")
// So we have to strip the baseurl manually -/
if (HTMLArea.is_ie && (name == "href" || name == "src")) {
value = editor.stripBaseURL(value);
}
}
} else { // IE fails to put style in attributes list
// FIXME: cssText reported by IE is UPPERCASE
value = root.style.cssText;
}
if (/(_moz|^$)/.test(value)) {
// Mozilla reports some special tags
// here; we don't need them.
continue;
}
html += " " + name + '="' + value + '"';
}
html += closed ? " />" : ">";
}
for (i = root.firstChild; i; i = i.nextSibling) {
html += HTMLArea.getHTML(i, true, editor);
}
if (outputRoot && !closed) {
html += "</" + root.tagName.toLowerCase() + ">";
}
break;
case 3: // Node.TEXT_NODE
// If a text node is alone in an element and all spaces, replace it with an non breaking one
// This partially undoes the damage done by moz, which translates ' 's into spaces in the data element
if ( !root.previousSibling && !root.nextSibling && root.data.match(/^\s*$/i) ) html = ' ';
else html = HTMLArea.htmlEncode(root.data);
break;
case 8: // Node.COMMENT_NODE
html = "<!--" + root.data + "-->";
break; // skip comments, for now.
}
return html;
};