W3C home > Mailing lists > Public > public-svg-wg@w3.org > July to September 2012

svg2-tools: Fixes for validation and to output XHTML5.

From: SVG Working Group repository <cam@mcc.id.au>
Date: Mon, 20 Aug 2012 19:26:04 -0700
Message-Id: <hg.fc11ef98626e.1345515964.2168319282941016272@ps58493.dreamhostps.com>
To: public-svg-wg@w3.org
details:   https://svgwg.org/hg/svg2-tools/rev/fc11ef98626e
branches:  
changeset: 57:fc11ef98626e
user:      Cameron McCormack <cam@mcc.id.au>
date:      Tue Aug 21 12:26:32 2012 +1000
description:
Fixes for validation and to output XHTML5.

diffstat:

 publish/definitions.js |   2 +-
 publish/processing.js  |  45 ++++++++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 10 deletions(-)

diffs (208 lines):

diff --git a/publish/definitions.js b/publish/definitions.js
--- a/publish/definitions.js
+++ b/publish/definitions.js
@@ -413,17 +413,17 @@ function loadInto(filename, base, defs) 
 
   forEachChild(doc.documentElement, 'term', function(t) {
     var term = new Term({
       name: t.getAttribute('name'),
       href: utils.resolveURL(base, t.getAttribute('href')),
     });
 
     if (t.firstChild) {
-      term.markup = t;
+      term.markup = utils.cloneChildren(t);
     }
 
     defs.terms[normalizeTermName(term.name)] = term;
   });
 }
 
 function resolve(defs) {
   for (var name in defs.elements) {
diff --git a/publish/processing.js b/publish/processing.js
--- a/publish/processing.js
+++ b/publish/processing.js
@@ -171,17 +171,17 @@ function hasElementSummaryTables(n) {
   return false;
 }
 
 exports.addExpanderScript = function(conf, page, doc) {
   if (!hasElementSummaryTables(doc)) {
     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>'));
 }
 
 
 // -- Add chapter number to <h1> and Table of Contents below it ---------------
 
 function generateTOC(conf, page, className) {
   function newTOCUL() {
     return utils.parse('<ul class="{{class}}"></ul>', { class: className });
@@ -199,17 +199,19 @@ function generateTOC(conf, page, classNa
         a.appendChild(utils.parse('<span class="secno">{{number}}{{section}}.</span> ',
                                   { number: conf.isSingleChapter ? '' : conf.pages[page].formattedNumber + '.',
                                     section: item.section.number }));
       }
       a.appendChild(item.section.title.cloneNode(true));
       if (item.children) {
         var childUL = newTOCUL();
         generate(childUL, item.children);
-        li.appendChild(childUL);
+        if (childUL.firstChild) {
+          li.appendChild(childUL);
+        }
       }
       ul.appendChild(li);
     }
   }
 
   var ul = newTOCUL();
   var sectionHierarchy = conf.getSectionHierarchy(page);
   if (sectionHierarchy && sectionHierarchy.children) {
@@ -335,17 +337,20 @@ function doFullTOC(conf, page, n) {
                         li.firstChild);
       } else if (pageType == 'appendix') {
         li.firstChild.insertBefore(utils.parse('Appendix {{number}}: ',
                                                { number: conf.pages[pageName].formattedNumber }),
                                    li.firstChild.firstChild);
       }
 
       if (pageType != 'page') {
-        li.appendChild(generateTOC(conf, pageName, 'toc'));
+        var pageTOC = generateTOC(conf, pageName, 'toc');
+        if (pageTOC.firstChild) {
+          li.appendChild(pageTOC);
+        }
       }
 
       ul.appendChild(li);
     }
   }
 
   utils.replace(n, ul);
 }
@@ -470,17 +475,18 @@ function formatElementAttributes(conf, e
   });
 
   return ul;
 }
 
 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;
 }
 
 function doElementSummary(conf, page, n) {
   var name = n.getAttribute('name');
   var element = conf.definitions.elements[name];
   var e = utils.parse('<div class="element-summary"><div class="element-summary-name"><span class="element-name">€˜{{name}}€™</span></div><dl>' +
@@ -534,29 +540,29 @@ function doIncludeLatestEditorsDraft(con
                                { href: conf.versions.cvs }));
 }
 
 function doPreviousVersion(conf, page, n) {
   replaceWithURLLink(n, conf.versions.previous);
 }
 
 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 }));
 }
 
 function doLocalLink(conf, page, n) {
   var href = utils.resolveURL(conf.thisVersion, n.getAttribute('href'));
   utils.replace(n, utils.parse('<a href="{{href}}">{{content}}</a>',
                                { href: href,
                                  content: n.firstChild ? utils.cloneChildren(n) : href }));
 }
 
 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) {
       attributes.push([[a.name, e.name].toString(), a.formatLink(true), [e.formatLink(true)], a.animatable]);
     });
   });
   utils.values(conf.definitions.attributeCategories).forEach(function(cat) {
     var elements =
@@ -595,17 +601,17 @@ function doAttributeTable(conf, page, n)
                                               elements: utils.fragment(a[2], ', '),
                                               animatable: a[3] ? 'œ“' : '' }));
   });
   utils.replace(n, table);
 }
 
 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);
 }
 
 function doElementCategory(conf, page, n) {
   var cat = conf.definitions.elementCategories[n.getAttribute('name')];
   var elts = cat.elements.concat().sort();
   utils.replace(n, utils.englishList(elts.map(function(e) { return conf.definitions.formatElementLink(e) })));
@@ -712,26 +718,47 @@ exports.formatMarkup = function(conf, pa
             n.parentNode.insertBefore(a[i], n);
           }
           n.parentNode.removeChild(n);
           return a;
         } else {
           n.parentNode.removeChild(n);
         }
       }
+      n.removeAttribute("edit:toc");
     }
   });
 
   // Remove the XML declaration "processing instruction".
   if (doc.firstChild.nodeType == doc.PROCESSING_INSTRUCTION_NODE) {
     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);
 };
 
 
 // -- Handle automatic linking with <a>. --------------------------------------
 
 exports.processLinks = function(conf, page, doc) {
   function shouldOmitQuotes(n) {
     if (n.parentNode.localName != 'th') {
Received on Tuesday, 21 August 2012 02:27:09 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 21 August 2012 02:27:09 GMT