svg2-tools: Allow selective inclusion of markup when publishing as a ...

Allow selective inclusion of markup when publishing as a not-ED.

diffstat:

 publish/processing.js |  11 +++++++++--
 publish/utils.js      |  17 +++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diffs (94 lines):

diff --git a/publish/processing.js b/publish/processing.js
--- a/publish/processing.js
+++ b/publish/processing.js
@@ -647,16 +647,22 @@ function doElementsWithAttributeCategory
   var elements = 
     utils.values(conf.definitions.elements)
       .filter(function(e) { return e.attributeCategories.indexOf(category) != -1 })
       .sort(function(a, b) { return utils.compare(a.name, b.name) })
       .map(function(e) { return e.formatLink(omitQuotes) });
   utils.replace(n, utils.englishList(elements));
 }
 
+function doWhenPublished(conf, page, n) {
+  if (conf.maturity != 'ED') {
+    return utils.replaceWithChildren(n);
+  }
+}
+
 exports.processReplacements = function(conf, page, doc) {
   var replacementFunctions = {
     minitoc: doMiniTOC,
     fulltoc: doFullTOC,
     completeidl: doCompleteIDL,
     interface: doInterface,
     example: doExample,
     includefile: doIncludeFile,
@@ -668,27 +674,28 @@ exports.processReplacements = function(c
     includelatesteditorsdraft: doIncludeLatestEditorsDraft,
     previousversion: doPreviousVersion,
     copyright: doCopyright,
     locallink: doLocalLink,
     attributetable: doAttributeTable,
     elementindex: doElementIndex,
     elementcategory: doElementCategory,
     attributecategory: doAttributeCategory,
-    elementswithattributecategory: doElementsWithAttributeCategory
+    elementswithattributecategory: doElementsWithAttributeCategory,
+    whenpublished: doWhenPublished
   };
 
   utils.forEachNode(doc, function(n) {
     if (n.nodeType == n.ELEMENT_NODE &&
         n.namespaceURI == namespaces.edit &&
         n.localName != 'with') {
       if (!replacementFunctions[n.localName]) {
         utils.warn('unknown element "edit:' + n.localName + '"', n);
       } else {
-        replacementFunctions[n.localName](conf, page, n);
+        return replacementFunctions[n.localName](conf, page, n);
       }
     }
   });
 };
 
 
 // -- Format the DOM so that it serializes nicely -----------------------------
 
diff --git a/publish/utils.js b/publish/utils.js
--- a/publish/utils.js
+++ b/publish/utils.js
@@ -156,16 +156,33 @@ exports.initialuc = function(s) {
   if (s == '') return '';
   return s.substring(0, 1).toUpperCase() + s.substring(1);
 };
 
 exports.replace = function(n, replacement) {
   n.parentNode.replaceChild(replacement, n);
 };
 
+exports.replaceWithChildren = function(n) {
+  var doc = n.ownerDocument;
+  var frag = doc.createDocumentFragment();
+  var children = exports.children(n);
+  children.forEach(frag.appendChild.bind(frag));
+  n.parentNode.replaceChild(frag, n);
+  return children;
+};
+
+exports.children = function(n) {
+  var a = [];
+  for (n = n.firstChild; n; n = n.nextSibling) {
+    a.push(n);
+  }
+  return a;
+};
+
 exports.englishList = function(items) {
   if (!items.length) {
     return undefined;
   }
   var doc = items[0].ownerDocument;
   var frag = doc.createDocumentFragment();
   for (var i = 0; i < items.length; i++) {
     if (i != 0) {

Received on Friday, 5 April 2013 07:34:19 UTC