Opened 10 years ago

Closed 9 years ago

#275 closed enhancement (fixed)

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)

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 (11)

comment:1 Changed 10 years ago by niko

  • Description modified (diff)

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

comment:2 Changed 10 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.

comment:3 Changed 10 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?

comment:4 Changed 10 years ago by gogo

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

comment:5 Changed 10 years ago by gogo

  • Resolution set to fixed
  • Status changed from new to closed

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.

comment:6 Changed 10 years ago by niko

nice!
much thanks for that!!

comment:7 Changed 10 years ago by ianb@…

  • Resolution fixed deleted
  • Status changed from closed to reopened

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)

comment:8 Changed 10 years ago by gogo

  • Milestone set to Version 1.0
  • Priority changed from normal to low

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).

comment:9 Changed 10 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/

comment:10 Changed 10 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()

comment:11 Changed 9 years ago by gogo

  • Resolution set to fixed
  • Status changed from reopened to closed

Closing this one.

Note: See TracTickets for help on using tickets.