diff --git a/v3/pwiki/parser.js b/v3/pwiki/parser.js index ec8c3e9..c04ac9c 100644 --- a/v3/pwiki/parser.js +++ b/v3/pwiki/parser.js @@ -1313,18 +1313,7 @@ module.parser = { // content handler... handler ??= function(page, body, path, text, state){ - return args.isolated ? - this.resolve( - page, - text, - args.isolated == 'partial' ? - serialize.partialDeepCopy(state) - : {}) - : this.expand(page, text, state) } - - var pageHandler = - function([path, text]){ - // recursion... + // check for recursion... // XXX for some reason this does not work for async... // ...and works quite differently in tests and // in console -- returns [object Object] in the @@ -1336,24 +1325,39 @@ module.parser = { return that.expand(page, recursive, state) } include_stack.push(path) - // XXX cache??? + // XXX check cache??? - // call the handler... + var res = args.isolated ? + this.resolve( + page, + text, + Object.assign( + args.isolated == 'partial' ? + serialize.partialDeepCopy(state) + : {}, + {include_stack})) + : this.expand(page, text, state) + + // handle recursion... + return Promise.awaitOrRun( + res, + function(){ + state.include_stack.at(-1) == src + && state.include_stack.pop() + // cleanup... + if(state.include_stack.length == 0){ + delete state.include_stack + delete state.recursive } + + return res }) } + + var pageHandler = + function([path, text]){ + // handle nested promises... return Promise.awaitOrRun( text, function(text){ - return Promise.awaitOrRun( - handler.call(that, page, body, path, text, state), - function(res){ - // recursion - state.include_stack.at(-1) == src - && state.include_stack.pop() - // cleanup... - if(state.include_stack.length == 0){ - delete state.include_stack - delete state.recursive } - - return res }) }) } + return handler.call(that, page, body, path, text, state) }) } // get and run things... return Promise.awaitOrRun(