1.1.0 • Published 9 years ago
block-nested v1.1.0
block-nested
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 ...
}
}
})