mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 02:50:08 +00:00 
			
		
		
		
	more work on attr support... still need testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									e39bab97e0
								
							
						
					
					
						commit
						c85531dc12
					
				| @ -208,6 +208,7 @@ var attributes = { | ||||
| 	//	.parseBlockAttrs(<text>[, <elem>])
 | ||||
| 	//		-> [<elem>, <attrs>, <sys-attrs>]
 | ||||
| 	//
 | ||||
| 	// XXX add attributes set in elem but not present in code to attrs/sysattrs...
 | ||||
| 	// XXX where should we get .__block_attrs__???
 | ||||
| 	// 		...editor (current), plugin, ...???
 | ||||
| 	// XXX might be a good idea to split out the actual code handler to 
 | ||||
| @ -234,13 +235,17 @@ var attributes = { | ||||
| 				   				true | ||||
| 							: val == 'false' ? | ||||
| 								false | ||||
| 							: val  | ||||
| 						// keep non-system attrs...
 | ||||
| 						if(!(name in system)){ | ||||
| 							attrs += `\n${name}::${val}` | ||||
| 						} else { | ||||
| 							sysattrs += `\n${name}::${val}` } } | ||||
| 							: val } | ||||
| 					return ws }) | ||||
| 		// NOTE: we are not doing this in the loop above to include all 
 | ||||
| 		// 		the attributes that are in the elem but not explicitly 
 | ||||
| 		// 		given in code...
 | ||||
| 		for(var name in elem){ | ||||
| 			var val = elem[name] | ||||
| 			if(!(name in system)){ | ||||
| 				attrs += `\n${name}::${val}` | ||||
| 			} else { | ||||
| 				sysattrs += `\n${name}::${val}` } } | ||||
| 		return [ | ||||
| 			elem,  | ||||
| 			attrs,  | ||||
| @ -248,26 +253,46 @@ var attributes = { | ||||
| 		] }, | ||||
| 
 | ||||
| 	// generate code...
 | ||||
| 	// 
 | ||||
| 	// this is controlled by the value of editor.__code_attrs__:
 | ||||
| 	// 	false / undefined	- strip attrs
 | ||||
| 	// 	true				- add attrs to code if available
 | ||||
| 	// 	'all'				- add attrs, including system attrs to 
 | ||||
| 	// 						  code if available,
 | ||||
| 	__parse_code__: function(code, editor, elem){ | ||||
| 		var [elem, attrs, system] = this.parseBlockAttrs(editor, code, elem) | ||||
| 		return !editor.__code_attrs__ ? | ||||
| 				elem.text | ||||
| 			: editor.__code_attrs__ == 'all' ? | ||||
| 				elem.text +'\n'+ attrs +'\n'+ system | ||||
| 			: elem.text +'\n'+ attrs }, | ||||
| 				elem.text  | ||||
| 					+ (attrs.length > 0 ?  | ||||
| 						'\n'+ attrs | ||||
| 						: '') | ||||
| 					+ (system.length > 0 ? | ||||
| 						'\n'+ system | ||||
| 						: '') | ||||
| 			: attrs.length > 0 ? | ||||
| 				elem.text +'\n'+ attrs  | ||||
| 			: elem.text }, | ||||
| 
 | ||||
| 	// generate view...
 | ||||
| 	//
 | ||||
| 	// this is controlled by the value of editor.__view_attrs__:
 | ||||
| 	// 	false / undefined	- strip attrs
 | ||||
| 	// 	true				- call the handler XXX
 | ||||
| 	__pre_parse__: function(text, editor, elem){ | ||||
| 		// NOTE: we are intentionally neglecting system attrs here...
 | ||||
| 		var [elem, attrs, system] = this.parseBlockAttrs(editor, text, elem) | ||||
| 		// XXX use filter handler here...
 | ||||
| 		return !editor.__view_attrs__ ? | ||||
| 			elem.text  | ||||
| 			: elem.text +'\n'+ attrs | ||||
| 	}, | ||||
| 		if(editor.__view_attrs__  | ||||
| 				&& attrs.length > 0){ | ||||
| 			attrs = editor.threadPlugins('__parse_attrs__', attrs, editor, elem) | ||||
| 			if(attrs && attrs.length > 0){ | ||||
| 				return text +'\n'+ attrs } } | ||||
| 		return elem.text }, | ||||
| 
 | ||||
| 	// XXX
 | ||||
| 	__parse_attrs__: function(){ | ||||
| 		// XXX
 | ||||
| 	} | ||||
| 	//__parse_attrs__: function(attrs, editor, elem){
 | ||||
| 	//	return attrs }
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -143,25 +143,11 @@ var setup = function(){ | ||||
|   - | ||||
| - ## ToDo: | ||||
|   - ASAP: expand sub-tree on follow link... | ||||
|   - ASAP: attributes: finalize base mechanics: | ||||
|     - code filtering | ||||
|       ``` | ||||
|       .__code_attrs__(attrs, code, elem) | ||||
|           -> true | ||||
|           -> false | ||||
|       ``` | ||||
|       _system attrs are always hidden, the client can control whether the code is shown or not_ | ||||
| 	- view filtering | ||||
|       ``` | ||||
|       .__view_attrs__(attrs, code, elem) | ||||
|           -> str | ||||
|           -> undefined | ||||
|       ``` | ||||
|     - might be a good idea to change `.parseBlockAttrs(..)` to return an array of text and attrs (str) and handle the above `.__code_attrs__(..)` and `.__view_attrs__(..)` in the respective handlers... | ||||
|   - ASAP TEST: attributes: finalize base mechanics... | ||||
|   - attributes: need to show/hide the attributes -- option? | ||||
|     attr::value | ||||
|     - `.__parse_code__(..)`: add data attributes to code if missing... | ||||
|     - do we need `.__code_attrs__` / `.__view_attrs__`???  | ||||
|     - DONE `.__parse_code__(..)`: add data attributes to code if missing... | ||||
|     - DONE do we need `.__code_attrs__` / `.__view_attrs__`??? -- YES | ||||
|     - handle attr delete correctly -- i.e. if shown attr removed from code -> delete attr... | ||||
|     - BUG? can't set `''` as attr value -- parser?? | ||||
|   - TOC: tweaking: add args like depth, ... -- as attributes... | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user