mirror of
https://github.com/tenrok/BBob.git
synced 2026-05-30 15:24:05 +03:00
50 lines
997 B
JavaScript
50 lines
997 B
JavaScript
const parser = require('@bbob/parser');
|
|
const render = require('@bbob/html');
|
|
|
|
const { iterate, match } = require('./utils');
|
|
|
|
function walk(cb) {
|
|
return iterate(this, cb);
|
|
}
|
|
|
|
module.exports = function bbob(plugs) {
|
|
const plugins = typeof plugs === 'function' ? [plugs] : plugs || [];
|
|
|
|
let options = {
|
|
skipParse: false,
|
|
};
|
|
|
|
return {
|
|
process(input, opts) {
|
|
options = opts || {};
|
|
|
|
const parseFn = options.parser || parser;
|
|
const renderFn = options.render || render;
|
|
|
|
let tree = options.skipParse
|
|
? input || []
|
|
: parseFn(input, options);
|
|
|
|
tree.walk = walk;
|
|
tree.match = match;
|
|
|
|
plugins.forEach((plugin) => {
|
|
tree = plugin(tree, {
|
|
parse: parseFn,
|
|
render: renderFn,
|
|
iterate,
|
|
match,
|
|
}) || tree;
|
|
});
|
|
|
|
return {
|
|
get html() {
|
|
return renderFn(tree, tree.options);
|
|
},
|
|
tree,
|
|
messages: tree.messages,
|
|
};
|
|
},
|
|
};
|
|
};
|