MarkdownHelper implements Helper<Object> { @Override public Object apply(final Object context, final Options options) throws IOException { if (options.isFalsy(context)) { return ""; } String markdown = context.toString(); PegDownProcessor processor = new PegDownProcessor(); return new Handlebars.SafeString(processor.markdownToHtml(markdown)); }  @Override Object apply(final Object context, final Options options); static final Helper<Object> INSTANCE; }
@Test public void markdownFalsy() throws IOException { Handlebars handlebars = new Handlebars(); handlebars.registerHelper("markdown", new MarkdownHelper()); Template template = handlebars.compileInline("{{markdown this}}"); assertEquals("", template.apply(null)); }
@Test public void markdown() throws IOException { String text = ""; text += "# Header 1\n"; text += "* Item 1\n"; text += "* Item 2\n"; text += "* Item 3\n\n"; text += "## Header 2\n"; Handlebars handlebars = new Handlebars(); handlebars.registerHelper("markdown", new MarkdownHelper()); Template template = handlebars.compileInline("{{markdown .}}"); String expected = "<h1>Header 1</h1>\n" + "<ul>\n" + " <li>Item 1</li>\n" + " <li>Item 2</li>\n" + " <li>Item 3</li>\n" + "</ul>\n" + "<h2>Header 2</h2>"; assertEquals(expected, template.apply(text)); }