diff --git a/CHANGES.md b/CHANGES.md
index 7134ffc..bd88ae9 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,6 +1,7 @@
# mustache.js Changes
## 0.3.0 (??-??-????)
+* Added higher order sections.
## 0.2.3 (28-03-2010)
diff --git a/README.md b/README.md
index 0eea4e2..7c1e8e0 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +88,34 @@ the items. Use `{{.}}` to access the current item inside the enumeration section
Joe's shopping card:
+### Higher Order Sections
+
+If a section key returns a function, it will be called and passed both the unrendered
+block of text and a renderer convenience function.
+
+Given this JS:
+
+ "name": "Tater",
+ "bolder": function() {
+ return function(text, render) {
+ return "" + render(text) + ''
+ }
+ }
+
+And this template:
+
+ {{#bolder}}Hi {{name}}.{{/bolder}}
+
+We'll get this output:
+
+ Hi Tater.
+
+As you can see, we're pre-processing the text in the block. This can be used to
+implement caching, filters (like syntax highlighting), etc.
+
+You can use `this.name` to access the attribute `name` from your view.
+
+
### View Partials
mustache.js supports a quite powerful but yet simple view partial mechanism. Use the
diff --git a/examples/higher_order_sections.html b/examples/higher_order_sections.html
new file mode 100644
index 0000000..04f5318
--- /dev/null
+++ b/examples/higher_order_sections.html
@@ -0,0 +1 @@
+{{#bolder}}Hi {{name}}.{{/bolder}}
diff --git a/examples/higher_order_sections.js b/examples/higher_order_sections.js
new file mode 100644
index 0000000..c7e558e
--- /dev/null
+++ b/examples/higher_order_sections.js
@@ -0,0 +1,9 @@
+var higher_order_sections = {
+ "name": "Tater",
+ "helper": "To tinker?",
+ "bolder": function() {
+ return function(text, render) {
+ return "" + render(text) + ' ' + this.helper;
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/higher_order_sections.txt b/examples/higher_order_sections.txt
new file mode 100644
index 0000000..9db786a
--- /dev/null
+++ b/examples/higher_order_sections.txt
@@ -0,0 +1 @@
+Hi Tater. To tinker?
diff --git a/mustache.js b/mustache.js
index 3ff899c..4a73e22 100644
--- a/mustache.js
+++ b/mustache.js
@@ -109,6 +109,11 @@ var Mustache = function() {
return that.render(content, that.merge(context,
that.create_context(row)), partials, true);
}).join("");
+ } else if(typeof value === "function") {
+ // higher order section
+ return value.call(context, content, function(text) {
+ return that.render(text, context, partials, true);
+ })
} else if(value) { // boolean section
return that.render(content, context, partials, true);
} else {