UNPKG

@podlite/schema

Version:

AST tools for Podlite markup language

29 lines 1.1 kB
const middle = () => tree => { const visit_node = (node, context = {}) => { // if( (node.type || "").match(/(code|text)/) ) { if (node.type == 'code' || node.type == 'text') { if (node.margin && context.margin && context.margin.length > 0 && context.margin.length == node.margin.length) { ; node.type = 'para'; } if (node.type === 'code') { // remove parent margin var regex = new RegExp(`^[ \t]{0,${node.margin.length}}`, 'gm'); node.text = node.text.replace(regex, ''); } } if (node.type === 'block') { context.margin = typeof node.margin !== 'string' ? '' : node.margin; let newctx = { ...context }; newctx.nest = (newctx.nest || 0) + 1; node.content.map(n => { visit_node(n, context); }); } }; var ctx = {}; tree.forEach(n => visit_node(n, ctx)); return tree; }; export default middle; //# sourceMappingURL=plugin-vmargin.js.map