block-nested

1.1.0 • Public • Published

block-nested

travis-ci

Block nested template syntax.

Usage

var Parser = require('block-nested')({
    /\{%[\s\S]+?%\}/g, // tags match RegExp
    // first match self-close tag
    // this judge condition is base on the condition of operator match
    function isSelfCloseTag (c) {
        return /\{%[\s\S]+?\/%\}/.test(c)
    },
    // secondary match block-open tag
    // this judge condition is base on the condition of operator match
    function isOpenTag (c) {
        return !/\{%\/[\s\S]+?%\}/.test(c)
    },
    function handler(ast) {
        switch (ast.type) {
            case 'close':
                // Do something with selft-close tag
                // ast.tag ...
            case 'block':
                // Do something with block-tag
                // ast.open, ast.close, ast.tag ...
        }
    }
})

Package Sidebar

Install

npm i block-nested

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • switer