mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-30 02:20:08 +00:00 
			
		
		
		
	cleanup and some fixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									b711a2937e
								
							
						
					
					
						commit
						effeac728b
					
				| @ -780,6 +780,7 @@ object.Constructor('Page', BasePage, { | |||||||
| 		// NOTE: the filter argument has the same semantics as the filter 
 | 		// NOTE: the filter argument has the same semantics as the filter 
 | ||||||
| 		// 		macro with one exception, when used in quote, the body is 
 | 		// 		macro with one exception, when used in quote, the body is 
 | ||||||
| 		// 		not expanded...
 | 		// 		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...
 | 		// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
 | ||||||
| 		quote: Macro( | 		quote: Macro( | ||||||
| @ -817,19 +818,19 @@ object.Constructor('Page', BasePage, { | |||||||
| 				// NOTE: since the body of quote(..) only has filters applied 
 | 				// NOTE: since the body of quote(..) only has filters applied 
 | ||||||
| 				// 		to it doing the first stage of .filter(..) as late 
 | 				// 		to it doing the first stage of .filter(..) as late 
 | ||||||
| 				// 		as the second stage here will have no ill effect...
 | 				// 		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...
 | 					// add global quote-filters...
 | ||||||
| 					filters = | 					filters = | ||||||
| 						(state.quote_filters  | 						(state.quote_filters  | ||||||
| 								&& !(filters ?? []).includes(this.ISOLATED_FILTERS)) ? | 								&& !(filters ?? []).includes(this.ISOLATED_FILTERS)) ? | ||||||
| 							[...state.quote_filters, ...(filters ?? [])] | 							[...state.quote_filters, ...(filters ?? [])] | ||||||
| 							: filters | 							: filters | ||||||
| 					if(filters){ | 					return filters ? | ||||||
| 						filters = Object.fromEntries(Object.entries(filters)) | 						await this.__parser__.callMacro( | ||||||
| 						return this.macros.filter | 								this, 'filter', filters, text, state, false) | ||||||
| 							.call(this, filters, text, state, false) | 							.call(this, state) | ||||||
| 							.call(this, state) } | 						: text } }), | ||||||
| 					return text } }), |  | ||||||
| 		// very similar to @filter(..) but will affect @quote(..) filters...
 | 		// very similar to @filter(..) but will affect @quote(..) filters...
 | ||||||
| 		'quote-filter': function(args, body, state){ | 		'quote-filter': function(args, body, state){ | ||||||
| 			var filters = state.quote_filters =  | 			var filters = state.quote_filters =  | ||||||
|  | |||||||
| @ -148,8 +148,7 @@ module.BaseParser = { | |||||||
| 	// NOTE: arg pre-parsing is dome by .lex(..) but at that stage we do not
 | 	// 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)
 | 	// 		yet touch the actual macros (we need them to get the .arg_spec)
 | ||||||
| 	// 		so the actual parsing is done in .expand(..)
 | 	// 		so the actual parsing is done in .expand(..)
 | ||||||
| 	parseArgs: function(spec, args, state){ | 	parseArgs: function(spec, args){ | ||||||
| 		var that = this |  | ||||||
| 		// spec...
 | 		// spec...
 | ||||||
| 		var order = spec.slice() | 		var order = spec.slice() | ||||||
| 		var bools = new Set( | 		var bools = new Set( | ||||||
| @ -179,6 +178,16 @@ module.BaseParser = { | |||||||
| 					(res[e] = true) | 					(res[e] = true) | ||||||
| 					: (res[order.shift()] = e) }) | 					: (res[order.shift()] = e) }) | ||||||
| 		return res }, | 		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...
 | 	// Strip comments...
 | ||||||
| @ -415,16 +424,11 @@ module.BaseParser = { | |||||||
| 			// nested macro -- skip...
 | 			// nested macro -- skip...
 | ||||||
| 			if(typeof(page.macros[name]) != 'function'){ | 			if(typeof(page.macros[name]) != 'function'){ | ||||||
| 				continue } | 				continue } | ||||||
| 			// args...
 | 
 | ||||||
| 			args = this.parseArgs.call(page, |  | ||||||
| 				page.macros[name].arg_spec  |  | ||||||
| 					?? [],  |  | ||||||
| 				args, |  | ||||||
| 				state) |  | ||||||
| 			// call...
 |  | ||||||
| 			var res =  | 			var res =  | ||||||
| 				await page.macros[name].call(page, args, body, state, value) | 				await this.callMacro(page, name, args, body, state)  | ||||||
| 					?? '' | 					?? '' | ||||||
|  | 
 | ||||||
| 			// result...
 | 			// result...
 | ||||||
| 			if(res instanceof Array  | 			if(res instanceof Array  | ||||||
| 					|| page.macros[name] instanceof types.Generator){ | 					|| page.macros[name] instanceof types.Generator){ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user