diff --git a/v3/pwiki/parser.js b/v3/pwiki/parser.js
index 140ba80..8fff0e5 100644
--- a/v3/pwiki/parser.js
+++ b/v3/pwiki/parser.js
@@ -1308,12 +1308,11 @@ module.parser = {
recursive ??= ''
var base = page.basepath
- // XXX we do this before or after we parse???
- var src = page.resolvePathVars(args.src)
-
return Promise.awaitOrRun(
- this.parseNested(page, src, state),
+ this.parseNested(page, args.src, state),
function(src){
+ //src = page.resolvePathVars(src)
+
// XXX should this be a tree??
// ...need to at least split direct and
// indirect dependencies...
@@ -1431,7 +1430,7 @@ module.parser = {
var that = this
return this.macros['include'].call(this,
page, args, body, state,
- function(page, src, text, state){
+ function(page, body, path, text, state){
return that.expand(page, text, state) }) }),
// Load macro and slot definitions but ignore the page text...
@@ -1442,7 +1441,8 @@ module.parser = {
function(page, args, body, state){
var that = this
return Promise.awaitOrRun(
- this.macros['include'].call(this, page, args, body, state),
+ this.macros['include'].call(this,
+ page, {src: args.src}, body, state),
function(){
return '' }) }),
@@ -1485,6 +1485,7 @@ module.parser = {
args.src
&& this.parseNested(page, args.src, state),
function(src){
+ //src = page.resolvePathVars(src)
var text =
src ?
page.get(src).raw
@@ -1494,20 +1495,6 @@ module.parser = {
return Promise.awaitOrRun(
text,
function(text){
- // XXX not sure I like that this has two "modes"...
- text = src && body ?
- // XXX do we need to account for generators???
- (text instanceof Array ?
- text
- : [text])
- .map(function(text){
- return that.expand(
- page,
- that.ast(body.join(''), false, 'quote'),
- state,
- { content: function(){
- return text }, }) })
- : text
return that.joinBlocks(
page,
that.filterBlocks(
@@ -1582,40 +1569,20 @@ module.parser = {
// get macro...
} else if(name){
body = (state.macros ?? {})[name] }
+
+ // else...
+ if(args.src
+ && !page.get(args.src).exists()){
+ for(var elem of body){
+ if(elem.name == 'else'){
+ body = elem.body
+ return that.expand(page.get(args.src), elem.body, state) } } }
+
return args.src && body ?
// run macro...
that.macros.include.call(that, page, args, body, state,
function(page, body, path, text, state){
- var that = this
-
- var handle = function(page, text, state){
- return args.isolated ?
- that.resolve(
- page,
- text,
- Object.assign(
- args.isolated == 'partial' ?
- serialize.partialDeepCopy(state)
- : {},
- {include_stack: state.include_stack ?? []}))
- : that.expand(page, text, state) }
-
- //var content_handled = false
- return body ?
- // handle body / ...
- Promise.awaitOrRun(
- that.expand(page.get(path), body, state,
- { content: function(){
- content_handled = true
- return text = handle(page, text, state) } }),
- function(text){
- // if no present we still
- // need to handle the included page...
- //content_handled
- // || handle.call(that, page, text, state)
- return text })
- // place as-is...
- : handle(page, text, state) })
+ return this.expand(page.get(path), body, state) })
: '' }) })),
// nesting rules...
diff --git a/v3/pwiki/test/parser.js b/v3/pwiki/test/parser.js
index 08d74b9..16106c8 100755
--- a/v3/pwiki/test/parser.js
+++ b/v3/pwiki/test/parser.js
@@ -56,6 +56,9 @@ module.exports.P = {
get matched(){
var path_action_pattern = /\/path\/?/
var path = this.path.replace(path_action_pattern, '')
+ path = path == '' ?
+ '/'
+ : path
var path_action = path != this.path
if(path.includes('*')){
@@ -72,17 +75,27 @@ module.exports.P = {
: [] })
.flat() }
return [this.path] },
+ exists: function(path){
+ var that = this
+ return (path ?
+ this.get(path).matched
+ : this.matched)
+ .filter(function(p){
+ return p in that.__pages__ })
+ .length > 0 },
// * -> a promise or a list of promises???
get raw(){
var res = []
var path_action_pattern = /\/path\/?/
- var path_action = this.path.match(path_action_pattern)
+ var path_action = path_action_pattern.test(this.path)
for(var path of this.matched){
res.push(
path_action ?
- path.replace(path_action_pattern, '')
+ ((path = path.replace(path_action_pattern, '')) == '' ?
+ '/'
+ : path)
: this.__pages__[path]) }
return res.length == 1 ?
@@ -315,13 +328,7 @@ test.Setups({
// quote...
// for inline quoting see: test.Modifiers.quote
- // XXX
- quote_content: function(assert, path='/isolated'){
- return {
- page: P,
- code: [
- '[[ ]]
',
- '[[ '+ P.get(path).raw +' ]]', ], } },
+ // XXX
// XXX macro...
// XXX