Change warning output format. Omit quotes around property links in property tables.
authorCameron McCormack <cam@mcc.id.au>
Sat, 18 Aug 2012 16:43:31 +1000
changeset 45 b511935ac513
parent 44 2ba98eae4634
child 46 45101ee54e7a
Change warning output format. Omit quotes around property links in property tables.
publish/definitions.js
publish/processing.js
publish/utils.js
--- a/publish/definitions.js	Fri Aug 17 17:29:23 2012 +1000
+++ b/publish/definitions.js	Sat Aug 18 16:43:31 2012 +1000
@@ -6,23 +6,28 @@
   if (properties) utils.extend(this, properties);
 }
 
-Element.prototype.formatLink = function() {
-  return utils.parse('<span class="element-name">‘<a href="{{href}}"><span>{{name}}</span></a>’</span>',
+Element.prototype.formatLink = function(omitQuotes) {
+  return utils.parse('<span class="element-name">{{lquote}}<a href="{{href}}"><span>{{name}}</span></a>{{rquote}}</span>',
                      { href: this.href,
-                       name: this.name });
+                       name: this.name,
+                       lquote: omitQuotes ? '' : '‘',
+                       rquote: omitQuotes ? '' : '’' });
 };
 
 function Attribute(properties) {
   if (properties) utils.extend(this, properties);
 }
 
-Attribute.prototype.formatLink = function(title) {
-  if (this.property && !title) {
+Attribute.prototype.formatLink = function(omitQuotes) {
+  var title;
+  if (this.property) {
     title = 'Presentation attribute for property ‘' + utils.encode(this.property) + '’';
   }
-  var span = utils.parse('<span class="attr-name">‘<a href="{{href}}"><span>{{name}}</span></a>’</span>',
+  var span = utils.parse('<span class="attr-name">{{lquote}}<a href="{{href}}"><span>{{name}}</span></a>{{rquote}}</span>',
                          { href: this.href,
-                           name: this.name });
+                           name: this.name,
+                           lquote: omitQuotes ? '' : '‘',
+                           rquote: omitQuotes ? '' : '’' });
   if (title) {
     span.firstChild.nextSibling.setAttribute('title', title);
   }
@@ -33,10 +38,12 @@
   if (properties) utils.extend(this, properties);
 }
 
-Property.prototype.formatLink = function() {
-  return utils.parse('‘<a href="{{href}}"><code class="property">{{name}}</code></a>’',
+Property.prototype.formatLink = function(omitQuotes) {
+  return utils.parse('{{lquote}}<a href="{{href}}"><code class="property">{{name}}</code></a>{{rquote}}',
                      { href: this.href,
-                       name: this.name });
+                       name: this.name,
+                       lquote: omitQuotes ? '' : '‘',
+                       rquote: omitQuotes ? '' : '’' });
 };
 
 function Symbol(properties) {
@@ -163,12 +170,12 @@
   return utils.parse('<span class="xxx">@@ unknown attribute "{{attribute}}"</span>', { attribute: attributeName });
 };
 
-Definitions.prototype.formatPropertyLink = function(name, n) {
+Definitions.prototype.formatPropertyLink = function(name, n, omitQuotes) {
   if (!this.properties[name]) {
     utils.warn('unknown property "' + name + '"', n);
     return utils.parse('<span class="xxx">@@ unknown property "{{name}}"</span>', { name: name });
   }
-  return this.properties[name].formatLink();
+  return this.properties[name].formatLink(omitQuotes);
 };
 
 Definitions.prototype.formatPresentationAttributeLink = function(name, n) {
@@ -260,7 +267,7 @@
   return null;
 }
 
-Definitions.prototype.formatNameLink = function(name, context) {
+Definitions.prototype.formatNameLink = function(name, context, omitQuotes) {
   var elementName = getElementContext(this, context);
   var element = this.elements[name];
   var attribute = elementName && this.elements[elementName].attributes[name] || this.commonAttributes[name];
@@ -289,7 +296,7 @@
     utils.warn('ambiguous name "' + name + '" matching ' + types.join(" and "), context);
     return utils.parse('<span class="xxx">@@ ambiguous name "{{name}}" (matches {{types}})</span>', { name: name, types: types.join(' and ') });
   }
-  return (element || attribute || property).formatLink();
+  return (element || attribute || property).formatLink(omitQuotes);
 };
 
 function loadInto(filename, base, defs) {
--- a/publish/processing.js	Fri Aug 17 17:29:23 2012 +1000
+++ b/publish/processing.js	Sat Aug 18 16:43:31 2012 +1000
@@ -709,6 +709,18 @@
 // -- Handle automatic linking with <a>. --------------------------------------
 
 exports.processLinks = function(conf, page, doc) {
+  function shouldOmitQuotes(n) {
+    if (n.parentNode.localName != 'th') {
+      return false;
+    }
+
+    while (n.localName != 'table') {
+      n = n.parentNode;
+    }
+
+    return n.getAttribute("class") == 'proptable';
+  }
+
   utils.forEachNode(doc, function(n) {
     if (n.nodeType != n.ELEMENT_NODE ||
         n.localName != 'a' ||
@@ -724,13 +736,13 @@
     } else if (/^'(\S+)\s+attribute'$/.test(text)) {
       utils.replace(n, conf.definitions.formatAttributeLink(RegExp.$1, n));
     } else if (/^'(\S+)\s+property'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatPropertyLink(RegExp.$1, n));
+      utils.replace(n, conf.definitions.formatPropertyLink(RegExp.$1, n, shouldOmitQuotes(n)));
     } else if (/^'(\S+)\s+presentationattribute'$/.test(text)) {
       utils.replace(n, conf.definitions.formatPresentationAttributeLink(RegExp.$1, n));
     } else if (/^'([^\/]+)\/([^\/]+)'$/.test(text)) {
       utils.replace(n, conf.definitions.formatElementAttributeLink(RegExp.$1, RegExp.$2, n));
     } else if (/^'(\S+)'$/.test(text)) {
-      utils.replace(n, conf.definitions.formatNameLink(RegExp.$1, n));
+      utils.replace(n, conf.definitions.formatNameLink(RegExp.$1, n, shouldOmitQuotes(n)));
     } else if (/^([^:]+)::([^:]+)$/.test(text)) {
       var interfaceName = RegExp.$1;
       var memberName = RegExp.$2;
--- a/publish/utils.js	Fri Aug 17 17:29:23 2012 +1000
+++ b/publish/utils.js	Sat Aug 18 16:43:31 2012 +1000
@@ -6,20 +6,20 @@
     DOMParser = require('xmldom').DOMParser,
     XMLSerializer = require('xmldom').XMLSerializer;
 
-exports.parseXML = function(filename) {
+parseXML = function(filename, type) {
   var parser = new DOMParser();
   parser.recordPositions = true;
-  var doc = parser.parseFromString(String(fs.readFileSync(filename)));
+  var doc = parser.parseFromString(String(fs.readFileSync(filename)), type);
   doc.documentURI = filename;
   return doc;
 };
 
+exports.parseXML = function(filename) {
+  return parseXML(filename);
+};
+
 exports.parseXHTML = function(filename) {
-  var parser = new DOMParser();
-  parser.recordPositions = true;
-  var doc = parser.parseFromString(String(fs.readFileSync(filename)), "/xhtml");
-  doc.documentURI = filename;
-  return doc;
+  return parseXML(filename, "/xhtml");
 };
 
 function fillParameter(n, parameter) {
@@ -240,5 +240,9 @@
 };
 
 exports.warn = function(message, node) {
-  console.warn('warning: ' + message + (node ? ', at ' + node.ownerDocument.documentURI + ':' + node.lineNumber + ':' + node.columnNumber : ''));
+  if (node) {
+    console.warn([node.ownerDocument.documentURI, node.lineNumber, node.columnNumber, ' warning: ' + message].join(':'));
+  } else {
+    console.warn('warning: ' + message);
+  }
 };