From 30907579eb8c5e60624ac824dcf3cd7110ab6682 Mon Sep 17 00:00:00 2001 From: Nat Pryce Date: Mon, 22 Jul 2013 22:45:28 +0100 Subject: [PATCH] README describes user-extensible escaping rules (not just HTML or no escaping) --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 80d65e9..072adca 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,29 @@ You can change the default HTML escaping behavior when obtaining a compiler: // result: // not: <bar> +User-defined escaping rules +--------------------------- + +You can change the escaping behavior when obtaining a compiler, to support file formats other than HTML and plain text. + +Implement the Escaping interface. If you only need to replace fixed strings in the text, you can subclass SimpleEscaping: + + public class StrangeFormatEscaping extends SimpleEscaping { + public StrangeFormatEscaping() { + super(new String[][] { + {"[", "[["}, + {"]", "]]"} + }); + } + +Pass an instance of your Escaping implementation when obtaining a compiler: + + Mustache.compiler().escape(new StrangeFormatEscaping()).compile("{{foo}}").execute(new Object() { + String foo = "[bar]"; + }); + // result: [[bar]] + + Special variables -----------------