mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00: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>])
|
// .parseBlockAttrs(<text>[, <elem>])
|
||||||
// -> [<elem>, <attrs>, <sys-attrs>]
|
// -> [<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__???
|
// XXX where should we get .__block_attrs__???
|
||||||
// ...editor (current), plugin, ...???
|
// ...editor (current), plugin, ...???
|
||||||
// XXX might be a good idea to split out the actual code handler to
|
// XXX might be a good idea to split out the actual code handler to
|
||||||
@ -234,13 +235,17 @@ var attributes = {
|
|||||||
true
|
true
|
||||||
: val == 'false' ?
|
: val == 'false' ?
|
||||||
false
|
false
|
||||||
: val
|
: val }
|
||||||
// keep non-system attrs...
|
|
||||||
if(!(name in system)){
|
|
||||||
attrs += `\n${name}::${val}`
|
|
||||||
} else {
|
|
||||||
sysattrs += `\n${name}::${val}` } }
|
|
||||||
return ws })
|
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 [
|
return [
|
||||||
elem,
|
elem,
|
||||||
attrs,
|
attrs,
|
||||||
@ -248,26 +253,46 @@ var attributes = {
|
|||||||
] },
|
] },
|
||||||
|
|
||||||
// generate code...
|
// 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){
|
__parse_code__: function(code, editor, elem){
|
||||||
var [elem, attrs, system] = this.parseBlockAttrs(editor, code, elem)
|
var [elem, attrs, system] = this.parseBlockAttrs(editor, code, elem)
|
||||||
return !editor.__code_attrs__ ?
|
return !editor.__code_attrs__ ?
|
||||||
elem.text
|
elem.text
|
||||||
: editor.__code_attrs__ == 'all' ?
|
: editor.__code_attrs__ == 'all' ?
|
||||||
elem.text +'\n'+ attrs +'\n'+ system
|
elem.text
|
||||||
: elem.text +'\n'+ attrs },
|
+ (attrs.length > 0 ?
|
||||||
|
'\n'+ attrs
|
||||||
|
: '')
|
||||||
|
+ (system.length > 0 ?
|
||||||
|
'\n'+ system
|
||||||
|
: '')
|
||||||
|
: attrs.length > 0 ?
|
||||||
|
elem.text +'\n'+ attrs
|
||||||
|
: elem.text },
|
||||||
|
|
||||||
// generate view...
|
// 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){
|
__pre_parse__: function(text, editor, elem){
|
||||||
|
// NOTE: we are intentionally neglecting system attrs here...
|
||||||
var [elem, attrs, system] = this.parseBlockAttrs(editor, text, elem)
|
var [elem, attrs, system] = this.parseBlockAttrs(editor, text, elem)
|
||||||
// XXX use filter handler here...
|
if(editor.__view_attrs__
|
||||||
return !editor.__view_attrs__ ?
|
&& attrs.length > 0){
|
||||||
elem.text
|
attrs = editor.threadPlugins('__parse_attrs__', attrs, editor, elem)
|
||||||
: elem.text +'\n'+ attrs
|
if(attrs && attrs.length > 0){
|
||||||
},
|
return text +'\n'+ attrs } }
|
||||||
|
return elem.text },
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
__parse_attrs__: function(){
|
//__parse_attrs__: function(attrs, editor, elem){
|
||||||
// XXX
|
// return attrs }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -143,25 +143,11 @@ var setup = function(){
|
|||||||
-
|
-
|
||||||
- ## ToDo:
|
- ## ToDo:
|
||||||
- ASAP: expand sub-tree on follow link...
|
- ASAP: expand sub-tree on follow link...
|
||||||
- ASAP: attributes: finalize base mechanics:
|
- ASAP TEST: 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...
|
|
||||||
- attributes: need to show/hide the attributes -- option?
|
- attributes: need to show/hide the attributes -- option?
|
||||||
attr::value
|
attr::value
|
||||||
- `.__parse_code__(..)`: add data attributes to code if missing...
|
- DONE `.__parse_code__(..)`: add data attributes to code if missing...
|
||||||
- do we need `.__code_attrs__` / `.__view_attrs__`???
|
- DONE do we need `.__code_attrs__` / `.__view_attrs__`??? -- YES
|
||||||
- handle attr delete correctly -- i.e. if shown attr removed from code -> delete attr...
|
- handle attr delete correctly -- i.e. if shown attr removed from code -> delete attr...
|
||||||
- BUG? can't set `''` as attr value -- parser??
|
- BUG? can't set `''` as attr value -- parser??
|
||||||
- TOC: tweaking: add args like depth, ... -- as attributes...
|
- TOC: tweaking: add args like depth, ... -- as attributes...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user