svg2-tools: Try putting content model elements in an inline list in e...

details:   https://svgwg.org/hg/svg2-tools/rev/6f7ca5478368
branches:  
changeset: 61:6f7ca5478368
user:      Cameron McCormack <cam@mcc.id.au>
date:      Tue Aug 21 17:29:06 2012 +1000
description:
Try putting content model elements in an inline list in element summary boxes.

diffstat:

 publish/definitions.js |   4 ++--
 publish/processing.js  |  19 ++++++++++---------
 publish/utils.js       |  17 ++++++++++++++++-
 3 files changed, 28 insertions(+), 12 deletions(-)

diffs (138 lines):

diff --git a/publish/definitions.js b/publish/definitions.js
--- a/publish/definitions.js
+++ b/publish/definitions.js
@@ -104,22 +104,22 @@ function Definitions() {
   this.interfaces = { };
   this.symbols = { };
   this.terms = { };
   this.commonAttributesForElements = [];
   this.commonAttributes = { };
   this.presentationAttributes = { };
 }
 
-Definitions.prototype.formatElementLink = function(name, n) {
+Definitions.prototype.formatElementLink = function(name, n, omitQuotes) {
   if (!this.elements[name]) {
     utils.warn('unknown element "' + name + '"', n);
     return utils.parse('<span class="xxx">@@ unknown element "{{name}}"</span>', { name: name });
   }
-  return this.elements[name].formatLink();
+  return this.elements[name].formatLink(omitQuotes);
 };
 
 Definitions.prototype.formatElementAttributeLink = function(elementName, attributeName, n) {
   if (!this.elements[elementName] || !this.elements[elementName].attributes[attributeName]) {
     utils.warn('unknown attribute "' + attributeName + '" on element "' + elementName + '"', n);
     return utils.parse('<span class="xxx">@@ unknown attribute "{{attribute}}" on element "{{element}}</span>', { attribute: attributeName, element: elementName });
   }
   return this.elements[elementName].attributes[attributeName].formatLink();
diff --git a/publish/processing.js b/publish/processing.js
--- a/publish/processing.js
+++ b/publish/processing.js
@@ -404,47 +404,48 @@ function formatContentModel(conf, elemen
     case 'text':
       return 'Character data.';
     default:
       return 'Empty.';
     case 'textoranyof':
       intro = 'Any number of the following elements or character data, in any order:';
       break;
     case 'anyof':
-      intro = 'Any number of the following elements or character data:';
+      intro = 'Any number of the following elements, in any order:';
       break;
     case 'oneormoreof':
-      intro = 'One or more of the following elements or character data:';
+      intro = 'One or more of the following elements, in any order:';
       break;
   }
 
+  var content = [intro];
+
   var ul = utils.parse('<ul class="no-bullets"></ul>');
   element.elementCategories.concat().sort().forEach(function(name) {
     var cat = conf.definitions.elementCategories[name];
     if (!cat) {
       return utils.parse('<li><a href="data:," style="background: red; color: white">@@ unknown element category "{{name}}"</a><li>', { name: name });
     }
     var li = utils.parse('<li><a href="{{href}}">{{name}} elements</a><span class="expanding"> — {{elements}}</span></li>',
                          { href: cat.href,
                            name: cat.name,
                            elements: utils.fragment(cat.elements.map(function(name) { return conf.definitions.formatElementLink(name, n) }), ', ') });
     ul.appendChild(li);
   });
+  content.push(ul);
 
-  element.elements.concat().sort().forEach(function(name) {
+  content.push(utils.list(element.elements.concat().sort().map(function(name) {
     var e = conf.definitions.elements[name];
     if (!e) {
-      return utils.parse('<li><a href="data:," style="background: red; color: white">@@ unknown element "{{name}}"</a><li>', { name: name });
+      return utils.parse('<a href="data:," style="background: red; color: white">@@ unknown element "{{name}}"</a>', { name: name });
     }
-    var li = utils.parse('<li>{{element}}</li>',
-                         { element: conf.definitions.formatElementLink(name, n) });
-    ul.appendChild(li);
-  });
+    return conf.definitions.formatElementLink(name, n, true);
+  })));
 
-  return [intro, ul];
+  return content;
 }
 
 function formatElementAttributes(conf, element, n) {
   if (!element.attributeCategories && !element.commonAttributes && !element.specificAttributes) {
     return "None";
   }
 
   var ul = utils.parse('<ul class="no-bullets"></ul>');
diff --git a/publish/utils.js b/publish/utils.js
--- a/publish/utils.js
+++ b/publish/utils.js
@@ -158,29 +158,44 @@ exports.initialuc = function(s) {
 };
 
 exports.replace = function(n, replacement) {
   n.parentNode.replaceChild(replacement, n);
 };
 
 exports.englishList = function(items) {
   if (!items.length) {
-    return null;
+    return undefined;
   }
   var doc = items[0].ownerDocument;
   var frag = doc.createDocumentFragment();
   for (var i = 0; i < items.length; i++) {
     if (i != 0) {
       frag.appendChild(doc.createTextNode(i == items.length - 1 ? ' and ' : ', '));
     }
     frag.appendChild(items[i]);
   }
   return frag;
 };
 
+exports.list = 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) {
+      frag.appendChild(doc.createTextNode(', '));
+    }
+    frag.appendChild(items[i]);
+  }
+  return frag;
+};
+
 exports.splitList = function(s) {
   if (!s) {
     return [];
   }
   return s.split(/,\s*/);
 };
 
 exports.values = function(object) {

Received on Tuesday, 21 August 2012 07:29:51 UTC