diff --git a/examples/whitespace_partial.2.html b/examples/whitespace_partial.2.html
new file mode 100644
index 0000000..9c46084
--- /dev/null
+++ b/examples/whitespace_partial.2.html
@@ -0,0 +1,5 @@
+Hello {{ name}}
+You have just won ${{value }}!
+{{# in_ca }}
+Well, ${{ taxed_value }}, after taxes.
+{{/ in_ca }}
diff --git a/examples/whitespace_partial.html b/examples/whitespace_partial.html
new file mode 100644
index 0000000..ce43cb3
--- /dev/null
+++ b/examples/whitespace_partial.html
@@ -0,0 +1,3 @@
+
{{ greeting }}
+{{> partial }}
+{{ farewell }}
\ No newline at end of file
diff --git a/examples/whitespace_partial.js b/examples/whitespace_partial.js
new file mode 100644
index 0000000..30ade55
--- /dev/null
+++ b/examples/whitespace_partial.js
@@ -0,0 +1,19 @@
+var partial_context = {
+ greeting: function() {
+ return "Welcome";
+ },
+
+ farewell: function() {
+ return "Fair enough, right?";
+ },
+
+ partial: {
+ name: "Chris",
+ value: 10000,
+ taxed_value: function() {
+ return this.value - (this.value * 0.4);
+ },
+ in_ca: true
+ }
+};
+
diff --git a/examples/whitespace_partial.txt b/examples/whitespace_partial.txt
new file mode 100644
index 0000000..160b0b6
--- /dev/null
+++ b/examples/whitespace_partial.txt
@@ -0,0 +1,6 @@
+Welcome
+Hello Chris
+You have just won $10000!
+Well, $6000, after taxes.
+
+Fair enough, right?
diff --git a/mustache.js b/mustache.js
index 4d48090..b6d60e4 100644
--- a/mustache.js
+++ b/mustache.js
@@ -84,6 +84,7 @@ var Mustache = function() {
Tries to find a partial in the global scope and render it
*/
render_partial: function(name, context, partials) {
+ name = this.trim(name);
if(!partials || !partials[name]) {
throw({message: "unknown_partial '" + name + "'"});
}
@@ -103,8 +104,8 @@ var Mustache = function() {
var that = this;
// CSW - Added "+?" so it finds the tighest bound, not the widest
- var regex = new RegExp(this.otag + "(\\^|\\#)(.+)" + this.ctag +
- "\\s*([\\s\\S]+?)" + this.otag + "\\/\\2" + this.ctag +
+ var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
+ "\\s*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag +
"\\s*", "mg");
// for each {{#foo}}{{/foo}} section do...