From 4449a9734d927d20da79a136cc80d536d83a2e2e Mon Sep 17 00:00:00 2001 From: "mkaply@us.ibm.com" Date: Wed, 13 Feb 2008 07:39:52 -0800 Subject: [PATCH] 416197 - r=sayrer, a=schrep - value excerpting only applies to child nodes --- .../microformats/src/Microformats.js | 53 ++++++++++--------- .../microformats/tests/test_Microformats.html | 12 ++++- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/toolkit/components/microformats/src/Microformats.js b/toolkit/components/microformats/src/Microformats.js index 9047b9f04d81..a676aadaf374 100644 --- a/toolkit/components/microformats/src/Microformats.js +++ b/toolkit/components/microformats/src/Microformats.js @@ -300,40 +300,45 @@ var Microformats = { return propnode.value; } else { var values = Microformats.getElementsByClassName(propnode, "value"); + /* Verify that values are children of the propnode */ + for (let i = values.length-1; i >= 0; i--) { + if (values[i].parentNode != propnode) { + values.splice(i,1); + } + } if (values.length > 0) { var value = ""; for (let j=0;j 0) { - return s; + s = propnode.textContent; } } + /* If we are processing a value node, don't remove whitespace */ + if (!Microformats.matchClass(propnode, "value")) { + /* Remove new lines, carriage returns and tabs */ + s = s.replace(/[\n\r\t]/gi, ' '); + /* Replace any double spaces with single spaces */ + s = s.replace(/\s{2,}/gi, ' '); + /* Remove any double spaces that are left */ + s = s.replace(/\s{2,}/gi, ''); + /* Remove any spaces at the beginning */ + s = s.replace(/^\s+/, ''); + /* Remove any spaces at the end */ + s = s.replace(/\s+$/, ''); + } + if (s.length > 0) { + return s; + } } }, /** diff --git a/toolkit/components/microformats/tests/test_Microformats.html b/toolkit/components/microformats/tests/test_Microformats.html index f1603c11a4fb..7f1057f44935 100644 --- a/toolkit/components/microformats/tests/test_Microformats.html +++ b/toolkit/components/microformats/tests/test_Microformats.html @@ -59,7 +59,13 @@ - +
+ + John + Middle + Doe + +
@@ -107,6 +113,10 @@ function test_Microformats() {
 
   var inner_parent = Microformats.getParent(document.getElementById("inner_vevent5"));
   is(inner_parent.id, "outer_tag5", "GetParent gets correct ancestor 5");
+  
+  var valueCard = new hCard(document.getElementById("value_test"));
+
+  is(valueCard.fn, "JohnDoe", "value_test");
 }
 
 function test_hCard() {