This library is simply a combination of Freemarker and PegDown. The use case is: You want to render Markdown but you also want to have the features from a template engine. Yes, you can combine such two libraries to do that. Or you can save time because I’ve done that for you: Here is FreeMarkerDown.
With FreeMarkerDown you can render an string as a FrreMarker template and after that it will be converted to Markdown. Additionaly you can process the template string before the rendering with pre processors.
final FreeMarkerDown fmd = FreeMarkerDown.create(); final Fragment template = fmd.createFragemnt( "# A Title\n" + "\n" + "<?fdm-keyvalue\n" + " key1: value one\n" + " key2: 42\n" + "?>\n" + "\n" + "Lorem ipsum dolor sit amet.\n" + "\n" + "## A List\n" + "\n" + "<#list sequence as item>\n" + "- ${item}\n" + "</#list>"); template.assignVariable("sequence", Arrays.asList("foo", "bar", "baz")); final Map<String, String> keyValues = Maps.newHashMap(); final PreProcessor processor = PreProcessors.createKeyValueProcessor(keyValues); fmd.register(processor); assertThat(fmd.render(template), is( "<h1>A Title</h1>" + "<p>Lorem ipsum dolor sit amet.</p>" + "<h2>A List</h2>\n" + "<ul>\n" + " <li>foo</li>\n" + " <li>bar</li>\n" + " <li>baz</li>\n" + "</ul>")); assertThat(keyValues.size(), is(2)); assertThat(keyValues, allOf(hasEntry("key1", "value one"), hasEntry("key2", "42")));
For more details how it works see the examples and architecture site.
Add this <dependency> to your Maven pom.xml:
<dependencies> <!-- ... --> <dependency> <groupId>de.weltraumschaf</groupId> <artifactId>freemarkerdown</artifactId> <version>1.0.0-beta</version> </dependency> <!-- ... --> <dependencies>
For manual instalation clone this repository and run Maven. You need at least Maven 3.0.3 or above installed:
$> git clone https://github.com/Weltraumschaf/freemarkerdown.git $> cd freemarkerdown $> mvn clean install
Or you can download the jar-file directly from the Maven Central Repository.
The examples in this project site is included with some Velocity macros.