diff --git a/pwiki/page.js b/pwiki/page.js index 0698231..852b4f9 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -583,6 +583,12 @@ object.Constructor('Page', BasePage, { return source .replace(/test/g, 'TEST') }, + 'quote-tags': function(source){ + return source + .replace(/&/g, '&') + .replace(//g, '>') }, + // XXX one way to do this in a stable manner is to wrap the source // in something like .. and only // process those removing the wrapper in dom... @@ -626,19 +632,13 @@ object.Constructor('Page', BasePage, { // // | - // + //* XXX filter: function(args, body, state, expand=true){ var that = this - var filters = state.filters = - state.filters ?? [] - // separate local filters... - if(body){ - var outer_filters = filters - filters = state.filters = - [outer_filters] } - // merge in new filters... + var outer = state.filters = + state.filters ?? [] var local = Object.keys(args) - filters.splice(filters.length, 0, ...local) // trigger quote-filter... var quote = local @@ -651,36 +651,30 @@ object.Constructor('Page', BasePage, { // local filters... if(body){ - // isolate from parent... - state.filters.includes(this.ISOLATED_FILTERS) - && state.filters[0] instanceof Array - && state.filters.shift() - // expand the body... var ast = expand ? - // XXX async... - //[...this.__parser__.expand(this, body, state)] this.__parser__.expand(this, body, state) : body instanceof Array ? body // NOTE: wrapping the body in an array effectively // escapes it from parsing... : [body] - filters = state.filters - state.filters = outer_filters - - // parse the body after we are done expanding... return async function(state){ - var outer_filters = state.filters - state.filters = this.__parser__.normalizeFilters(filters) + // XXX can we lose stuff from state this way??? + // ...at this stage it should more or less be static -- check! var res = - await this.parse(ast, state) - .iter() - .flat() - .join('') - state.filters = outer_filters - return { data: res } } } }, + await this.__parser__.filter(this, ast, { + ...state, + filters: local.includes(this.ISOLATED_FILTERS) ? + local + : [...outer, ...local], + }) + return {data: res} } + + // global filters... + } else { + state.filters = [...outer, ...local] } }, // // @include() // @@ -715,15 +709,12 @@ object.Constructor('Page', BasePage, { handler = handler ?? async function(src){ - return this.get(src) - .parse( - isolated ? - {seen: (state.seen ?? []).slice()} - : state) } + return isolated ? + {data: await this.get(src) + .parse({seen: (state.seen ?? []).slice()})} + : this.get(src) + .parse(state) } - // XXX this is really odd -- works OK for multiple pages - // and res turns into a string '[object Promise]' - // for a non-pattern page... return this.get(src) .each() .map(async function(page){ @@ -749,8 +740,7 @@ object.Constructor('Page', BasePage, { if(!parent_seen){ delete state.seen } - return res }) - .join('\n') }), + return res }) }), // NOTE: the main difference between this and @include is that // this renders the src in the context of current page while // include is rendered in the context of its page but with @@ -1116,14 +1106,6 @@ object.Constructor('Page', BasePage, { // render template in context of page... return this.get(path) .parse(await this.get(tpl).raw) }).call(this) }, - /*/ - var path = pwpath.split(this.path) - return [path.at(-1)[0] == '_' ? - await this.parse() - : await this.get('./'+ this.PAGE_TEMPLATE).parse()] - .flat() - .join('\n') }).call(this) }, - //*/ set text(value){ this.__update__({text: value}) }, //this.onTextUpdate(value) }, @@ -1240,10 +1222,16 @@ module.System = { // text: '- @source(.)' }, // _text: { - text: '@include(.)' }, + text: '@include(. isolated)' }, + // XXX this does not separate items when getting patterns... + //text: '@include(. isolated)' }, _raw: { text: '@quote(.)' }, + // XXX not sure if this is the right way to go... + _code: { + text: '
' }, + // base system pages... // diff --git a/pwiki/parser.js b/pwiki/parser.js index 7aa6e7b..1dff8c9 100755 --- a/pwiki/parser.js +++ b/pwiki/parser.js @@ -391,6 +391,7 @@ module.BaseParser = { // // // returned by .macros.filter(..) // | { + // // XXX is this still relevant... // filters: [ // '' // | '-', @@ -399,6 +400,9 @@ module.BaseParser = { // data: [ , .. ], // } // + // XXX macros: we are mixing up ast state and parse state... + // one should only be used for parsing and be forgotten after + // the ast is constructed the other should be part of the ast... expand: async function*(page, ast, state={}){ ast = ast == null ? //this.group(page) @@ -454,6 +458,7 @@ module.BaseParser = { // them on demand rather than on encounter (as is now), e.g. // a slot when loaded will replace the prior occurrences... // + // XXX this should be recursive.... // XXX add a special filter to clear pending filters... (???) parse: async function(page, ast, state={}){ var that = this @@ -474,8 +479,6 @@ module.BaseParser = { : section })) .flat() // filters... - // XXX if one of the post-handlers is a promise this will - // need to sync... .map(function(section){ return ( // expand section... @@ -496,6 +499,7 @@ module.BaseParser = { // will have no effect on the result... return page.filters[filter].call(page, res) ?? res }, section) + //*/ // no global filters... : section ) }) .flat() diff --git a/pwiki2-test.js b/pwiki2-test.js index 6749258..c43a2e9 100755 --- a/pwiki2-test.js +++ b/pwiki2-test.js @@ -58,13 +58,33 @@ pwiki.store.update('@pouch', { // XXX TEST... // XXX add filter tests... pwiki.pwiki + .update({ + location: '/test/test', + text: 'test', }) + .update({ + location: '/test/filter', + text: object.doc` + Should be: AAAAaaaaAAAAaaaa : testtest@include(../test)@include(../test isolated) + @filter(test) + `, }) + .update({ + location: '/test/filter-local', + text: object.doc` + Should be: aaaaAAAAaaaa : testtesttest + `, }) + .update({ + location: '/test/filter-isolated', + text: object.doc` + Should be: AAAAaaaaAAAA : testtesttest + @filter(test) + `, }) .update({ location: '/test/quote', text: object.doc` Inline quoted text: --- - this should not get expanded: @now() + this test should not get expanded: @now() --- @@ -75,12 +95,11 @@ pwiki.pwiki Quote filters: --- - - test filters... + + test ... --- - `, - }) + `, }) .update({ location: '/test/wikiword', text: object.doc` @@ -88,8 +107,7 @@ pwiki.pwiki the [basic] forms and Versions of /inline/links. - @filter(wikiword markdown) `, - }) + @filter(wikiword markdown) `, }) .update({ location: '/test/slots', text: object.doc` @@ -100,8 +118,7 @@ pwiki.pwiki ...while this (text should be replaced...) text is filling a slot - `, - }) + `, }) .update({ location: '/test/a', text: 'a', diff --git a/pwiki2.js b/pwiki2.js index e6656d7..0cc6a88 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,7 +1,7 @@ /********************************************************************** * * -* XXX BUG: .get('/*').raw hangs... +* XXX BUG: browser: .get('/*').raw hangs... * XXX add action to reset overloaded (bootstrap) pages... * - per page * - global