SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SGML style comments and quirks/standards mode in Firefox

    This is a rather advanced topic which probably would fit better in my weblog if I had one. But I don't. Anyway, in HTML, the following fragmet is a comment (three comments actually, the first and the last contain one whitespace, and the second contains the text "> this is a comment <!".)
    HTML Code:
    <!-- -- --> this is a comment <!-- -- -->
    Firefox supports this, but only in Standards mode. In Quirks mode, the fragment is parsed as two comments containing " -- ", and a text node " this is a comment ".

    File 1:
    HTML Code:
    <!-- -- --> this is a comment <!-- -- -->
    <title>foo</title>
    <p>bar
    This document is parsed in Quirks mode, so the text "this is a comment" shows up.

    File 2:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <!-- -- --> this is a comment <!-- -- -->
    <title>foo</title>
    <p>bar
    This document is parsed in Standards mode, so the text is inside a comment.

    So far so good, but what happens to the following document?

    File 3:
    HTML Code:
    <!-- -- -->
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <!-- -- -->
    <title>foo</title>
    <p>bar
    If it is parsed in Quirks mode, it should find the DOCTYPE and thus switch to Standards mode. If it is parsed in Standards mode it shouldn't find any DOCTYPE, and thus switch to Quirks mode.

    Paradox.

    In the end, the document is displayed in Standards mode, and when I view the source the DOCTYPE is inside a comment. But I don't understand the parsing sequence.
    Simon Pieters

  2. #2
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    UK, London
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand why you'd want to use
    Code:
    <!-- -- --> this is a comment <!-- -- -->
    when
    Code:
    <!-- this is a comment -->
    does the job wonderfully?
    Chris Heilmann
    Blog | Articles | Binaries

  3. #3
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's nothing I want to use, it's an experiment.

    This document:
    HTML Code:
    <!-- -- -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <!-- -- -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <TITLE>Title</TITLE>
    <P>Para
    ...is rendered in Standards mode, so I've come to the conclution that Firefox starts to parse in Quirks mode, and if it finds a DOCTYPE that triggers Standards mode, it starts over and parses the entire document in Standards mode without further DOCTYPE switching.
    Simon Pieters

  4. #4
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Yes, it seems to make sense plus some of them were half doctypes rather than full ones.

  5. #5
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since the rendering mode is determined by the doctype declaration, this raises an interesting point: does Gecko presume quirks mode until there is evidence to the contrary? Or does it presume standards mode until it realises that it's a cr*ppy document?

    From your description, it seems as it needs a doctype declaration that triggers standards mode, which is logical if you think about it. It should start by assuming quirks mode, because if there is no doctype declaration, it's already in the right mode.

    Although it's an interesting experiment, it's not something I'd recommend for use on a public site.

    I guess you'd better start a blog very soon, eh?
    Birnam wood is come to Dunsinane

  6. #6
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It does presume Quirks mode, otherwise this document would be rendered in Standards mode:
    HTML Code:
    <!-- -- -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <!-- -- -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <TITLE>Title</TITLE>
    <P>Para
    But it's rendered in Quirks mode.
    I guess you'd better start a blog very soon, eh?
    Yeah, probably...
    Edit:

    New findings! Gecko/20050806 presumes standards mode. "File 3" in #1 = quirks, #3 = quirks and #6 = standards.
    Last edited by zcorpan; Aug 8, 2005 at 07:16.
    Simon Pieters


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •