Skip to content

armano2/freemarker-parser

Repository files navigation

freemarker-parser

Codecov License npm

Freemarker Parser is a javascript implementation of the Freemarker (https://freemarker.apache.org).

This project contains experimental version of parser ftl to ast tree

Installation

You can install freemarker-parser using npm:

$ npm install freemarker-parser --save-dev

Usage

Require freemarker-parser inside of your JavaScript:

Parser

<#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);

Parser (bracket style)

[#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);

Currently supported:

TODO:

  • directives:
    • #fallback
    • #nested
    • #recurse
    • #visit