Skip to content

Latest commit

 

History

History
128 lines (104 loc) · 3.96 KB

README.md

File metadata and controls

128 lines (104 loc) · 3.96 KB

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