Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2005-08-10 17:59:03

megauser
New member
Registered: 2005-08-10
Posts: 5

Help needed please!

Hi!

I was pretty impressed to see that xinha utilizes some nice code formatting in textmode. Now, I am working with the original HtmlXrea editor (and not Xinha). I have to keep it and work on it for a few reasons (not going to dicuss these here).

I was told that the formatting is done in the getHTML and the getHTMLWrapper function. So I replaced my getHTML with the mentioned 2 functions (took out  _lc becouse it gave javascript error) The problem is that the program says "Your Document is not well formed. Check JavaScript console for details." and the formatting does not work.

PLEASE PLEASE SOMEBODY HELP. Can anyone modify my (HtmlArea's) getHTML funtion to have some king of formatting? I dont understand this part of the code. The code only has to work with Ms IE so dont have to bother with browser differences.
For reference I include the HtmlArea version of the getHTML function:
--------------
// 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) {
                    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;
};
----------
Thank You very much!

megaUser

Offline

#2 2005-08-11 02:36:56

mharrisonline
Xinha Administrator
From: Denver, Colorado
Registered: 2005-04-11
Posts: 110
Website

Re: Help needed please!

Take a look at ticket 275, it has code originally used in HTMLArea 3 for this. At the bottom of the ticket there is also a link to the original discussion and code on the HTMLArea user forum.

http://xinha.python-hosting.com/ticket/275

Offline

Board footer

Powered by FluxBB