[cc-devel] Malformed HTML in CC licences
Richard Smith
richard at ex-parrot.com
Thu Jan 5 07:23:00 EST 2012
Nathan Yergler wrote:
> Yikes. Regardless of whether they're well formed as XML, these do need
> to be well formed HTML to fulfill the promise that they operate as
> linked data documents.
Thanks for your reply. I agree it needs to be well-formed
HTML, but this needn't mean HTML 4. Everything I've read
that purports to be a standard on linked data documents
allows for XHTML dialects too. As the CC licences are
generated with 'transitional' XHTML 1.0 <!DOCTYPE>
declarations, presumably they are intended to be in that
dialect. And if so, well-formed XHTML 1.0 simply means
well-formed XML.
We can probably never have totally valid XHTML (as opposed
to well-formed XHTML) because the RDFa attributes such as
'about' and 'resource' are not valid XHTML. Nor are the
extra namespace declarations needed on the <html> element.
But parsers don't need to validate so that shouldn't be a
problem.
> In the case of the extraneous span close tag,
> that looks like a bug in the template
> (http://code.creativecommons.org/viewgit/cc.engine.git/tree/cc/engine/templates/licenses/standard_deed.html#n167)
> that's going to be present in every core deed generated.
I guessed there must have been a template somewhere, but
hadn't managed to locate it.
The </span> is the major problem here as it is the only one
current parsers are not reliable at recovering from, and
it's unambiguously an error: the line simply needs deleting.
Is posting here sufficient to get that fixed? If not, what
should I do?
But if we marking the document as XHTML and therefore XML,
we really should correct the other well-formedness issues.
The three unescaped ampersands are generated on this line:
http://code.creativecommons.org/viewgit/cc.engine.git/tree/cc/engine/templates/macros_templates/deed.html#n143
Each instances of '&' simply need replacing with '&'.
This is a legitimate (but not usually necessary) thing to do
in HTML 4, but is necessary with XHTML's stricter parsing
rules. A discussion on this incompatibility can be found
here:
http://www.w3.org/TR/xhtml1/#C_12
but the summary is that it is always a good idea to escape
the '&' in this manner.
The two unescaped '<' signs are generated on this line:
http://code.creativecommons.org/viewgit/cc.engine.git/tree/cc/engine/templates/macros_templates/deed.html#n163
In this context, HTML 4 prohibits '<' being escaped as <
while XHTML mandates it. For maximum compatibility we
probably want our document to work when parsed as HTML or as
XHTML, and there are two types of trick that can be used to
fix this. The most flexible is to use a <![CDATA]> section
that will appear to be commented out to a HTML 4 parser.
This is described here:
http://javascript.about.com/library/blxhtml.htm
We would simply change
document.write( ... );
to
/* <![CDATA[ */
document.write( ... );
/* ]]> */
These changes are all harmless to a HTML 4 parser, but make
the difference between the document being well-formed XHTML
or not.
Richard
More information about the cc-devel
mailing list