Ticket #275 (closed enhancement: fixed)

Opened 8 years ago

Last modified 8 years ago

Formats HTML source in IE

Reported by: mharrisonline Owned by: gogo
Priority: low Milestone: Version 1.0
Component: Xinha Core Version:
Severity: normal Keywords:
Cc:

Description (last modified by niko) (diff)

Currently when the source is viewed in IE there is no formatting. This modification is used in the Jones Standard implementation of Xinha and allows IE to format HTML to make it easier to read.

From on the nightly build for May 17, 2005:

Lines 4520 to 4533:

  if (/^(_moz)?$/.test(value)) {
          // Mozilla reports some special tags
          // here; we don't need them.
          continue;
        }
        html += " " + name + '="' + HTMLArea.htmlEncode(value) + '"';
      }
      if (html != "") {
        html += closed ? " />" : ">";
      }
    }
    for (i = root.firstChild; i; i = i.nextSibling) {
      html += HTMLArea.getHTMLWrapper(i, true, editor);
    }

Would change to:

        if (/^(_moz)?$/.test(value)) {
          // Mozilla reports some special tags
          // here; we don't need them.
          continue;
        }
        html += " " + name + '="' + HTMLArea.htmlEncode(value) + '"';
      }
      if (html != "") {
        html += closed ? " />" : ">";
      }
  // htmlarea formats HTML in IE, formatting gets lost otherwise, code doesn't work in Mozilla though 
        if (!HTMLArea.is_ie) { html += "";} else {html += "\r";}
 // end of modification	
    }
    for (i = root.firstChild; i; i = i.nextSibling) {
      html += HTMLArea.getHTMLWrapper(i, true, editor);
    }

Change History

Changed 8 years ago by niko

  • description modified (diff)

why += "\r" and not \n\r?

Changed 8 years ago by gogo

niko: should be \r\n. However \n is the Unix standard line termination, \r\n is the Windows world, and I believe older macs used \r only.

Changed 8 years ago by niko

thanks for correcting, i always make this mistake :(

however... what is a browser using now, the unix-version or the windows version? i would say IE uses \r\n but firefox?

Changed 8 years ago by gogo

I think browsers would handle either \r\n or \n fine.

Changed 8 years ago by gogo

  • status changed from new to closed
  • resolution set to fixed

I have added source code indentation for IE in changeset:170 slightly better than the submitter's, it indents block elements, inline elements are left, err, inline.

Gecko is untouched as it preserves newlines.

Changed 8 years ago by niko

nice! much thanks for that!!

Changed 8 years ago by ianb@…

  • status changed from closed to reopened
  • resolution deleted

Would it be possible to apply this to Gecko as well, perhaps as a configuration option? Gecko doesn't insert any extra whitespace into the source it generates, even if it preserves the whitespace of the source it gets (http://xinha.gogo.co.nz/punbb/viewtopic.php?id=228)

Changed 8 years ago by gogo

  • priority changed from normal to low
  • milestone set to Version 1.0

ian: yes, could do but we would have to strip newlines (except within <pre>, <script> and <style>) first then re-apply them, which means newlines won't be preserved in a text->gui->text cycle (of which there is always at least one).

Changed 8 years ago by mharrisonline

Wow! I can't believe how much you improved it! To give credit where credit is due, what I posted was based upon a solution provided by bjand in the post at:

http://www.htmlarea.com/forum/htmlArea_3_(beta)_C4/htmlArea_v3.0_-_Beta_Release_F14/html_output_is_one_%2Areally%2A_long_line%21_P17404/

Changed 8 years ago by troels_kn

Please take a look at the code I posted at ticket#253, witch not only formats the sourcecode nicely, but works equally in moz/ie and is way faster than the existing getHTML()

Changed 8 years ago by gogo

  • status changed from reopened to closed
  • resolution set to fixed

Closing this one.

Note: See TracTickets for help on using tickets.