Fixes for validation and to output XHTML5.
authorCameron McCormack <cam@mcc.id.au>
Tue, 21 Aug 2012 12:26:32 +1000
changeset 57 fc11ef98626e
parent 56 b2d9cbc10596
child 58 4f816c23b257
Fixes for validation and to output XHTML5.
publish/definitions.js
publish/processing.js
--- a/publish/definitions.js	Mon Aug 20 15:40:15 2012 +1000
+++ b/publish/definitions.js	Tue Aug 21 12:26:32 2012 +1000
@@ -418,7 +418,7 @@
     });
 
     if (t.firstChild) {
-      term.markup = t;
+      term.markup = utils.cloneChildren(t);
     }
 
     defs.terms[normalizeTermName(term.name)] = term;
--- a/publish/processing.js	Mon Aug 20 15:40:15 2012 +1000
+++ b/publish/processing.js	Tue Aug 21 12:26:32 2012 +1000
@@ -176,7 +176,7 @@
     return;
   }
 
-  doc.body.appendChild(utils.parse('<script src="style/expanders.js"></script>'));
+  doc.body.appendChild(utils.parse('<script src="style/expanders.js" type="text/javascript"></script>'));
 }
 
 
@@ -204,7 +204,9 @@
       if (item.children) {
         var childUL = newTOCUL();
         generate(childUL, item.children);
-        li.appendChild(childUL);
+        if (childUL.firstChild) {
+          li.appendChild(childUL);
+        }
       }
       ul.appendChild(li);
     }
@@ -340,7 +342,10 @@
       }
 
       if (pageType != 'page') {
-        li.appendChild(generateTOC(conf, pageName, 'toc'));
+        var pageTOC = generateTOC(conf, pageName, 'toc');
+        if (pageTOC.firstChild) {
+          li.appendChild(pageTOC);
+        }
       }
 
       ul.appendChild(li);
@@ -475,7 +480,8 @@
 function formatElementInterfaces(conf, element, n) {
   var ul = utils.parse('<ul class="no-bullets"></ul>');
   element.interfaces.forEach(function(name) {
-    ul.appendChild(conf.definitions.formatInterfaceLink(name, n));
+    ul.appendChild(utils.parse('<li>{{interface}}</li>',
+                               { interface: conf.definitions.formatInterfaceLink(name, n) }));
   });
   return ul;
 }
@@ -539,7 +545,7 @@
 }
 
 function doCopyright(conf, page, n) {
-  utils.replace(n, utils.parse('<p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © {{year}} <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>, <a href="http://www.ercim.eu/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p>',
+  utils.replace(n, utils.parse('<p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © {{year}} <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p>',
                                { year: conf.publicationYear }));
 }
 
@@ -551,7 +557,7 @@
 }
 
 function doAttributeTable(conf, page, n) {
-  var table = utils.parse('<table class="proptable attrtable" summary="Alphabetic list of attributes"><thead><tr><th>Attribute</th><th>Elements on which the attribute may be specified</th><th title="Animatable"><a href="animate.html#Animatable">Anim.</a></th></tr></thead><tbody></tbody></table>');
+  var table = utils.parse('<table class="proptable attrtable"><thead><tr><th>Attribute</th><th>Elements on which the attribute may be specified</th><th title="Animatable"><a href="animate.html#Animatable">Anim.</a></th></tr></thead><tbody></tbody></table>');
   var attributes = [];
   utils.values(conf.definitions.elements).forEach(function(e) {
     e.specificAttributes.forEach(function(a) {
@@ -600,7 +606,7 @@
 
 function doElementIndex(conf, page, n) {
   var elements = Object.keys(conf.definitions.elements).sort().map(function(name) { return conf.definitions.formatElementLink(name) });
-  var index = utils.parse('<ul class="element-index" summary="Alphabetic list of elements">{{elements}}</ul>',
+  var index = utils.parse('<ul class="element-index">{{elements}}</ul>',
                           { elements: elements.map(function(e) { return utils.parse('<li>{{link}}</li>', { link: e }) }) });
   utils.replace(n, index);
 }
@@ -717,6 +723,7 @@
           n.parentNode.removeChild(n);
         }
       }
+      n.removeAttribute("edit:toc");
     }
   });
 
@@ -725,8 +732,28 @@
     doc.removeChild(doc.firstChild);
   }
 
-  // Add a DOCTYPE.
-  doc.insertBefore(doc.implementation.createDocumentType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"), doc.firstChild);
+  // Remove any unnecessary xmlns="" attributes.
+  utils.forEachNode(doc.documentElement, function(n) {
+    if (n.nodeType == n.ELEMENT_NODE) {
+      if (n.parentNode.nodeType == n.ELEMENT_NODE &&
+          n.parentNode.namespaceURI == n.getAttribute("xmlns")) {
+        n.removeAttribute("xmlns");
+      }
+      n.removeAttribute("xmlns:edit");
+    }
+  });
+
+  // Replace any HTML4-style <meta http-equiv="Content-Type"> element with
+  // an HTML5-style <meta charset>.
+  var head = utils.child(doc.documentElement, 'head');
+  var meta = utils.child(head, 'meta');
+  if (meta) {
+    head.removeChild(meta);
+  }
+  head.insertBefore(utils.parse('<meta charset="UTF-8"/>'), head.firstChild);
+
+  // Add an HTML5 DOCTYPE.
+  doc.insertBefore(doc.implementation.createDocumentType("html", "", ""), doc.firstChild);
 };