Changeset 170


Ignore:
Timestamp:
05/18/05 18:16:29 (14 years ago)
Author:
gogo
Message:

Add indentation to getHTML for IE, which trashes newlines in the DOM
apparently.

See #275

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/htmlarea.js

    r169 r170  
    45044504} 
    45054505 
    4506 HTMLArea.getHTMLWrapper = function(root, outputRoot, editor) { 
     4506HTMLArea.getHTMLWrapper = function(root, outputRoot, editor, indent) { 
    45074507  var html = ""; 
     4508  if(!indent) indent = ''; 
     4509 
    45084510  switch (root.nodeType) { 
    45094511    case 10:// Node.DOCUMENT_TYPE_NODE 
     
    45244526      // Mozilla seems to convert CDATA into a comment when going into wysiwyg mode, 
    45254527      //  don't know about IE 
    4526       html += '<![CDATA[' + root.data + ']]>'; 
     4528      html += (HTMLArea.is_ie ? ('\n' + indent) : '') + '<![CDATA[' + root.data + ']]>' ; 
    45274529      break; 
    45284530 
     
    45344536      // PI's don't seem to survive going into the wysiwyg mode, (at least in moz) 
    45354537      // so this is purely academic 
    4536       html += '<?' + root.target + ' ' + root.data + ' ?>'; 
     4538      html += (HTMLArea.is_ie ? ('\n' + indent) : '') + '<?' + root.target + ' ' + root.data + ' ?>'; 
    45374539      break; 
    45384540 
     
    45514553    if (HTMLArea.is_ie && root_tag == "head") { 
    45524554      if (outputRoot) 
    4553         html += "<head>"; 
     4555        html += (HTMLArea.is_ie ? ('\n' + indent) : '') + "<head>"; 
    45544556      // lowercasize 
    45554557      var save_multiline = RegExp.multiline; 
     
    45594561      }); 
    45604562      RegExp.multiline = save_multiline; 
    4561       html += txt; 
     4563      html += txt + '\n'; 
    45624564      if (outputRoot) 
    4563         html += "</head>"; 
     4565        html += (HTMLArea.is_ie ? ('\n' + indent) : '') + "</head>"; 
    45644566      break; 
    45654567    } else if (outputRoot) { 
    45664568      closed = (!(root.hasChildNodes() || HTMLArea.needsClosingTag(root))); 
    4567       html = "<" + root.tagName.toLowerCase(); 
     4569      html += (HTMLArea.is_ie && HTMLArea.isBlockElement(root) ? ('\n' + indent) : '') + "<" + root.tagName.toLowerCase(); 
    45684570      var attrs = root.attributes; 
    45694571      for (i = 0; i < attrs.length; ++i) { 
     
    46194621      } 
    46204622    } 
     4623    var containsBlock = false; 
    46214624    for (i = root.firstChild; i; i = i.nextSibling) { 
    4622       html += HTMLArea.getHTMLWrapper(i, true, editor); 
     4625      if(!containsBlock && i.nodeType == 1 && HTMLArea.isBlockElement(i)) containsBlock = true; 
     4626      html += HTMLArea.getHTMLWrapper(i, true, editor, indent + '  '); 
    46234627    } 
    46244628    if (outputRoot && !closed) { 
    4625       html += "</" + root.tagName.toLowerCase() + ">"; 
     4629      html += (HTMLArea.is_ie && HTMLArea.isBlockElement(root) && containsBlock ? ('\n' + indent) : '') + "</" + root.tagName.toLowerCase() + ">"; 
    46264630    } 
    46274631    break; 
    46284632      } 
    46294633      case 3: // Node.TEXT_NODE 
    4630  
    4631     // If a text node is alone in an element and all spaces, replace it with an non breaking one 
    4632     // This partially undoes the damage done by moz, which translates '&nbsp;'s into spaces in the data element 
    4633  
    46344634    html = /^script|style$/i.test(root.parentNode.tagName) ? root.data : HTMLArea.htmlEncode(root.data); 
    46354635    break; 
     
    46374637      case 8: // Node.COMMENT_NODE 
    46384638    html = "<!--" + root.data + "-->"; 
    4639     break;              // skip comments, for now. 
     4639    break; 
    46404640  } 
    46414641  return html; 
Note: See TracChangeset for help on using the changeset viewer.