Allow selective inclusion of markup when publishing as a not-ED.
authorCameron McCormack <cam@mcc.id.au>
Fri, 05 Apr 2013 14:17:08 +1100
changeset 70 1ec0dc40d161
parent 69 63ff451f26c5
child 71 03c2ca802c74
Allow selective inclusion of markup when publishing as a not-ED.
publish/processing.js
publish/utils.js
--- a/publish/processing.js	Tue Apr 02 15:05:46 2013 +1100
+++ b/publish/processing.js	Fri Apr 05 14:17:08 2013 +1100
@@ -652,6 +652,12 @@
   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,
@@ -673,7 +679,8 @@
     elementindex: doElementIndex,
     elementcategory: doElementCategory,
     attributecategory: doAttributeCategory,
-    elementswithattributecategory: doElementsWithAttributeCategory
+    elementswithattributecategory: doElementsWithAttributeCategory,
+    whenpublished: doWhenPublished
   };
 
   utils.forEachNode(doc, function(n) {
@@ -683,7 +690,7 @@
       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);
       }
     }
   });
--- a/publish/utils.js	Tue Apr 02 15:05:46 2013 +1100
+++ b/publish/utils.js	Fri Apr 05 14:17:08 2013 +1100
@@ -161,6 +161,23 @@
   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;