W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2012

[whatwg] Proposal for window.DocumentType.prototype.toString

From: Johan Sundström <oyasumi@gmail.com>
Date: Mon, 29 Oct 2012 17:58:45 -0700
Message-ID: <CAGFhi3_rQeLW9TDAZMndiXggpARQEtN7zQUqYySjZ6PbP1Fb_Q@mail.gmail.com>
To: WHAT-WG list <whatwg@whatwg.org>
Hi everybody!

Serializing a complete HTML document DOM to a string is surprisingly
hard in javascript. As a fairly seasoned javascript hacker I figured
this might do it:

  document.doctype + document.documentElement.outerHTML

It doesn't. No browser has a useful window.DocumentType.prototype that
returns either the original document's <!DOCTYPE ...> before parsing –
or a semantically equivalent post-parsing one. Google Chrome shows one
in its devtools, but seems not to export some way of getting at it to

My proposal is we specify this more useful behaviour for
javascript-running browsers, so it does become as simple as above. A
rough sketch of how a polyfill might implement the latter


Even as a polyfill, the above is rather limited, though:  I believe
only Firefox implements "internalSubset" today, and probably only in
XML contexts. The most useful implementation would IMO be a native one
that reproducing the doctype, as it was formatted in the source


 / Johan Sundström, http://ecmanaut.blogspot.com/
Received on Tuesday, 30 October 2012 00:59:43 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:46 UTC