Index: openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/GetHtml/get-html.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/GetHtml/get-html.js,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/GetHtml/get-html.js 2 Nov 2005 08:56:01 -0000 1.1 +++ openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/GetHtml/get-html.js 11 Nov 2005 20:32:43 -0000 1.2 @@ -12,14 +12,15 @@ * - Returns correct code for Flash objects and scripts * - Formats html in an indented, readable format in html mode * - Preserves script and pre formatting + * - Preserves formatting in comments * - Removes contenteditable from body tag in full-page mode * - Supports only7BitPrintablesInURLs config option * - Supports htmlRemoveTags config option */ function GetHtml(editor) { this.editor = editor; -}; +} GetHtml._pluginInfo = { name : "GetHtml", @@ -44,12 +45,13 @@ /*11*/ new RegExp().compile(/\s+([^=\s]+)(="[^"]+")/g),// lowercase attribute names /*12*/ new RegExp().compile(/(\S*\s*=\s*)?contenteditable[^=>]*(=\s*[^>\s\/]*)?/gi),//strip contenteditable /*13*/ new RegExp().compile(/((href|src)=")([^\s]*)"/g), //find href and src for stripBaseHref() -/*14*/ new RegExp().compile(/<\/?(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|br|hr|img|embed|param|pre|script|html|head|body)[^>]*>/g), -/*15*/ new RegExp().compile(/<\/(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body)( [^>]*)?>/g),//blocklevel closing tag -/*16*/ new RegExp().compile(/<(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body)( [^>]*)?>/g),//blocklevel opening tag -/*17*/ new RegExp().compile(/<(br|hr|img|embed|param|pre|script)[^>]*>/g),//singlet tag +/*14*/ new RegExp().compile(/<\/?(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|br|hr|img|embed|param|pre|script|html|head|body|meta|link|title)[^>]*>/g), +/*15*/ new RegExp().compile(/<\/(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body|script)( [^>]*)?>/g),//blocklevel closing tag +/*16*/ new RegExp().compile(/<(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body|script)( [^>]*)?>/g),//blocklevel opening tag +/*17*/ new RegExp().compile(/<(br|hr|img|embed|param|pre|meta|link|title)[^>]*>/g),//singlet tag /*18*/ new RegExp().compile(/(^|<\/(pre|script)>)(\s|[^\s])*?(<(pre|script)[^>]*>|$)/g),//exclude content between pre and script tags -/*19*/ new RegExp().compile(/(]*>)(\s|[^\s])*?(<\/pre>)/g)//find content inside pre tags +/*19*/ new RegExp().compile(/(]*>)(\s|[^\s])*?(<\/pre>)/g),//find content inside pre tags +/*20*/ new RegExp().compile(/(^|)((\s|\S)*?)(?=|$)/g)//exclude comments ]; /** @@ -73,7 +75,7 @@ replace(c[10], ' ');//trim extra whitespace if(HTMLArea.is_ie && c[13].test(sHtml)) {// sHtml = sHtml.replace(c[13],'$1'+this.stripBaseURL(RegExp.$3)+'"'); - }; + } if(this.config.only7BitPrintablesInURLs && c[13].test(sHtml)) { sHtml = sHtml.replace(c[13], '$1'+RegExp.$3.replace(/([^!-~]+)/g,function(chr){return escape(chr);})+'"'); } @@ -91,7 +93,8 @@ if(HTMLArea.is_gecko) { //moz changes returns into
inside
 tags
 		s = s.replace(c[19], function(str){return str.replace(/
/g,"\n")}); } - s = s.replace(c[18], function(string) { + s = s.replace(c[20], function(st,$1,$2,$3) { //exclude comments + strn = $3.replace(c[18], function(string) { //skip pre and script tags string = string.replace(/[\n\r]/gi, " ").replace(/\s+/gi," ").replace(c[14], function(str) { if (str.match(c[16])) { var s = "\n" + HTMLArea.__sindent + str; @@ -114,6 +117,7 @@ return str; // this won't actually happen }); return string; + });return $1 + strn; }); if (s.charAt(0) == "\n") { return s.substring(1, s.length); @@ -133,32 +137,49 @@ for (j = temp.nextSibling; j; j = j.nextSibling) { temp.appendChild(j.cloneNode(true)); } - html += temp.innerHTML.replace(/<[^\?][^>]*>/gi, function(tag){return editor.cleanHTML(tag)}); + html += temp.innerHTML.replace(/<[^\?!][^>]*>/gi, function(tag){return editor.cleanHTML(tag)}); } else { - var root_tag = (root.nodeType == 1) ? root.tagName.toLowerCase() : ''; - if (outputRoot) { //only happens with tag in fullpage mode - html += "<" + root_tag + ">"; - } - - //pass tags to cleanHTML() one at a time; ignore php tags - //includes support for htmlRemoveTags config option - html += editor.getInnerHTML().replace(/<[^\?][^>]*>/gi, function(tag){ - if(!(editor.config.htmlRemoveTags && editor.config.htmlRemoveTags.test(tag.replace(/<([^\s>\/]+)/,'$1')))) - return editor.cleanHTML(tag); - else return ''}); - //IE drops all tags in a list except the last one - if(HTMLArea.is_ie) { - html = html.replace(/]*)?>/g,''). - replace(/(<(ul|ol)[^>]*>)[\s\n]*<\/li>/g, '$1'). - replace(/<\/li>([\s\n]*<\/li>)+/g, '<\/li>'); - } - if (outputRoot) { - html += ""; - } - html = HTMLArea.indent(html); -} + var root_tag = (root.nodeType == 1) ? root.tagName.toLowerCase() : ''; + if (outputRoot) { //only happens with tag in fullpage mode + html += "<" + root_tag; + var attrs = root.attributes; // strangely, this doesn't work in moz + for (i = 0; i < attrs.length; ++i) { + var a = attrs.item(i); + if (!a.specified) { + continue; + } + var name = a.nodeName.toLowerCase(); + var value = a.nodeValue; + html += " " + name + '="' + value + '"'; + } + html += ">"; + } + if(root_tag == "html") { + innerhtml = editor._doc.documentElement.innerHTML; + } else { + innerhtml = editor._doc.body.innerHTML; + } + //pass tags to cleanHTML() one at a time; ignore comments and php tags + //includes support for htmlRemoveTags config option + html += innerhtml.replace(/<[^\?!][^>]*>/gi, function(tag){ + if(!(editor.config.htmlRemoveTags && editor.config.htmlRemoveTags.test(tag.replace(/<([^\s>\/]+)/,'$1')))) + return editor.cleanHTML(tag); + else return ''}); + //IE drops all tags in a list except the last one + if(HTMLArea.is_ie) { + html = html.replace(/]*)?>/g,''). + replace(/(<(ul|ol)[^>]*>)[\s\n]*<\/li>/g, '$1'). + replace(/<\/li>([\s\n]*<\/li>)+/g, '<\/li>'); + } + if(HTMLArea.is_gecko) + html = html.replace(/(.*)
\n$/, '$1'); //strip trailing
added by moz + if (outputRoot) { + html += ""; + } + html = HTMLArea.indent(html); + }; // html = HTMLArea.htmlEncode(html); return html;