cleanup and some fixes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-08-13 17:02:32 +03:00
parent b711a2937e
commit effeac728b
2 changed files with 22 additions and 17 deletions

View File

@ -780,6 +780,7 @@ object.Constructor('Page', BasePage, {
// NOTE: the filter argument has the same semantics as the filter
// macro with one exception, when used in quote, the body is
// not expanded...
// NOTE: the filter argument uses the same filters as @filter(..)
//
// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
quote: Macro(
@ -817,19 +818,19 @@ object.Constructor('Page', BasePage, {
// NOTE: since the body of quote(..) only has filters applied
// to it doing the first stage of .filter(..) as late
// as the second stage here will have no ill effect...
return function(state){
// NOTE: this uses the same filters as @filter(..)
return async function(state){
// add global quote-filters...
filters =
(state.quote_filters
&& !(filters ?? []).includes(this.ISOLATED_FILTERS)) ?
[...state.quote_filters, ...(filters ?? [])]
: filters
if(filters){
filters = Object.fromEntries(Object.entries(filters))
return this.macros.filter
.call(this, filters, text, state, false)
.call(this, state) }
return text } }),
return filters ?
await this.__parser__.callMacro(
this, 'filter', filters, text, state, false)
.call(this, state)
: text } }),
// very similar to @filter(..) but will affect @quote(..) filters...
'quote-filter': function(args, body, state){
var filters = state.quote_filters =

View File

@ -148,8 +148,7 @@ module.BaseParser = {
// NOTE: arg pre-parsing is dome by .lex(..) but at that stage we do not
// yet touch the actual macros (we need them to get the .arg_spec)
// so the actual parsing is done in .expand(..)
parseArgs: function(spec, args, state){
var that = this
parseArgs: function(spec, args){
// spec...
var order = spec.slice()
var bools = new Set(
@ -179,6 +178,16 @@ module.BaseParser = {
(res[e] = true)
: (res[order.shift()] = e) })
return res },
// XXX should this be here or on page???
callMacro: function(page, name, args, body, state, ...rest){
return page.macros[name].call(page,
this.parseArgs(
page.macros[name].arg_spec
?? [],
args),
body,
state,
...rest) },
// Strip comments...
@ -415,16 +424,11 @@ module.BaseParser = {
// nested macro -- skip...
if(typeof(page.macros[name]) != 'function'){
continue }
// args...
args = this.parseArgs.call(page,
page.macros[name].arg_spec
?? [],
args,
state)
// call...
var res =
await page.macros[name].call(page, args, body, state, value)
await this.callMacro(page, name, args, body, state)
?? ''
// result...
if(res instanceof Array
|| page.macros[name] instanceof types.Generator){