From: Paul Duncan Date: 2006-01-21T07:12:45+09:00 Subject: [PATCH] Add XHTML 1.0 Output Support to Ruby CGI --Pql/uPZNXIm1JCle Content-Type: multipart/mixed; boundary="ryJZkp9/svQ58syV" Content-Disposition: inline --ryJZkp9/svQ58syV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The attached patch against Ruby 1.8.4 adds XHTML 1.0 output support to the Ruby CGI library. It should apply clean against Ruby 1.9 as well, although I haven't tried. =20 I've taken special care to _not_ change the output produced by non-XHTML output types; they should remain byte-for-byte compatible to the output generated by the Ruby CGI library without this patch (with one exception that is discussed way, way, way down at the bottom of this message). Also, any changes to the existing CGI API are in the form of additional method parameters which default to the old behavior. In other words, applications and libraries which depend on Ruby CGI will continue to work as expected without modification. XHTML documents are, by definition, also well-formed XML documents, which, in addition to the extra document type declarations, also means case-sensitive attribute and element names, balanced element tags, and quoted attribute values. With that in mind, here's a list of changes which apply to XHTML content generation: * Added three new output types: "xhtml10", "xhtml10Tr", and "xhtml10Fr", for XHTML 1.0 Strict, XHTML 1.0 Transitional, and=20 XHTML 1.0 Frameset, respectively. * Lower-cased element and attribute names. * Expand minimized attributes. * Balanced element tags. * Addition of an XML declaration. Here's an example that demonstrates each of these changes (the code that generates this output is attached as "ruby-1.8.4-xhtml_cgi_test.rb"): Here's the output produced by CGI.rb with an output type of 'html4': CGI Output Test (html4)

CGI = Output Test (html4)


This is a test HTML document.

this is a test of name mapping
Now, here's the same document, with an output type of 'xhtml10': CGI Output Tes= t (xhtml10)

CGI Output Test (xhtml10)


This is a t= est HTML document.

<=
code name=3D"id-map-test" id=3D"id-map-test">this is a test of name mapping=
Note the addition of an XML declaration after the document type declaration. While the XHTML spec doesn't _require_ an XML declaration, it strongly recommends it, especially if the document is being served with a content type of 'text/html'. I haven't changed the default Content-Type for XHTML output from the default value of 'text/html'; I'll elaborate on that a bit more later. I've also deliberately put the XML declaration after the DOCTYPE declaration. Even though my spidey sense tells me that it should be the other way around, the spec does not appear to require the XML declaration before the DOCTYPE declaration and, more importantly, certain browsers (hello, Internet Explorer!) behave incorrectly if the DOCTYPE declaration doesn't come first. Other obvious changes are the lower-case element and attribute names, balanced attributes ("
" vs "
") and terminating tags for elements such as