Freemarker Parser is a javascript implementation of the Freemarker (https://freemarker.apache.org).
This project contains experimental version of parser ftl to ast tree
You can install freemarker-parser
using npm:
$ npm install freemarker-parser --save-dev
Require freemarker-parser
inside of your JavaScript:
<#assign f=1>
<#if f gt 0>
${f} > 0
<#else>
${f} < 0
</#if>
const freemarker = require('freemarker-parser');
const parser = new freemarker.Parser();
const data = parser.parse(template);
console.log(data.ast);
console.log(data.tokens);
[#assign f=1]
[#if f gt 0]
${f} > 0
[#else]
${f} < 0
[/#if]
const freemarker = require('freemarker-parser');
const parser = new freemarker.Parser();
const data = parser.parse(template, {
useSquareTags: true,
parseLocation: true,
});
console.log(data.ast);
console.log(data.tokens);
- interpolations
${foo}
- methods, i.e.
${avg(3, 5)}
- methods, i.e.
- executing macro
- directives https://freemarker.apache.org/docs/ref_directives.html:
- comments
<#-- -->
- built-ins:
?toUpperCase
?toLowerCase
?capitalize
?length
?string("yes", "no")
- support default values, i.e.
${user!"Anonymous"}
- directives:
#fallback
#nested
#recurse
#visit