mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-30 02:20:08 +00:00
cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
3d8caaafb4
commit
f23f4c3c50
@ -5,10 +5,6 @@
|
|||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
// XXX
|
|
||||||
var PLUGIN_ATTRS = true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Helpers...
|
// Helpers...
|
||||||
@ -197,10 +193,22 @@ var plugin = {
|
|||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
// XXX PLUGIN_ATTRS
|
|
||||||
var attributes = {
|
var attributes = {
|
||||||
__proto__: plugin,
|
__proto__: plugin,
|
||||||
|
|
||||||
|
//
|
||||||
|
// Parse attrs...
|
||||||
|
// .parseBlockAttrs(<text>[, <elem>])
|
||||||
|
// -> <elem>
|
||||||
|
//
|
||||||
|
// Parse attrs keeping non-system attrs in .text...
|
||||||
|
// .parseBlockAttrs(<text>, true[, <elem>])
|
||||||
|
// -> <elem>
|
||||||
|
//
|
||||||
|
// Parse attrs keeping all attrs in .text...
|
||||||
|
// .parseBlockAttrs(<text>, 'all'[, <elem>])
|
||||||
|
// -> <elem>
|
||||||
|
//
|
||||||
// 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
|
||||||
@ -886,6 +894,15 @@ var escaping = {
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
var JSONOutline = {
|
var JSONOutline = {
|
||||||
|
|
||||||
|
__code_attrs__: false,
|
||||||
|
__view_attrs__: false,
|
||||||
|
__block_attrs__: {
|
||||||
|
id: 'attr',
|
||||||
|
collapsed: 'attr',
|
||||||
|
focused: 'cls',
|
||||||
|
},
|
||||||
|
|
||||||
// Plugins...
|
// Plugins...
|
||||||
//
|
//
|
||||||
// The order of plugins can be significant in the following cases:
|
// The order of plugins can be significant in the following cases:
|
||||||
@ -898,11 +915,7 @@ var JSONOutline = {
|
|||||||
//
|
//
|
||||||
// XXX split out DOM-specific plugins into Outline.plugins...
|
// XXX split out DOM-specific plugins into Outline.plugins...
|
||||||
pre_plugins: [
|
pre_plugins: [
|
||||||
// XXX PLUGIN_ATTRS
|
attributes,
|
||||||
...(PLUGIN_ATTRS ?
|
|
||||||
[attributes]
|
|
||||||
: []),
|
|
||||||
//*/
|
|
||||||
blocks,
|
blocks,
|
||||||
quoted,
|
quoted,
|
||||||
],
|
],
|
||||||
@ -1030,13 +1043,12 @@ var JSONOutline = {
|
|||||||
// .__post_parse__(..)
|
// .__post_parse__(..)
|
||||||
//
|
//
|
||||||
// XXX PRE_POST_NEWLINE can we avoid explicitly patching for empty lines after pre???
|
// XXX PRE_POST_NEWLINE can we avoid explicitly patching for empty lines after pre???
|
||||||
__view_attrs__: false,
|
|
||||||
__code2html__: function(code, elem={}){
|
__code2html__: function(code, elem={}){
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
// only whitespace -> keep element blank...
|
// only whitespace -> keep element blank...
|
||||||
|
elem.text = code
|
||||||
if(code.trim() == ''){
|
if(code.trim() == ''){
|
||||||
elem.text = code
|
|
||||||
return elem }
|
return elem }
|
||||||
|
|
||||||
// helpers...
|
// helpers...
|
||||||
@ -1048,13 +1060,6 @@ var JSONOutline = {
|
|||||||
}[stage]
|
}[stage]
|
||||||
return that.threadPlugins(meth, text, that, elem) }
|
return that.threadPlugins(meth, text, that, elem) }
|
||||||
|
|
||||||
if(PLUGIN_ATTRS){
|
|
||||||
elem.text = code
|
|
||||||
} else {
|
|
||||||
elem = this.parseBlockAttrs(code, this.__view_attrs__, elem)
|
|
||||||
code = elem.text
|
|
||||||
}
|
|
||||||
|
|
||||||
// stage: pre...
|
// stage: pre...
|
||||||
var text = run('pre',
|
var text = run('pre',
|
||||||
// pre-sanitize...
|
// pre-sanitize...
|
||||||
@ -1109,62 +1114,6 @@ var JSONOutline = {
|
|||||||
text.trim()
|
text.trim()
|
||||||
: text },
|
: text },
|
||||||
|
|
||||||
__block_attrs__: {
|
|
||||||
id: 'attr',
|
|
||||||
collapsed: 'attr',
|
|
||||||
focused: 'cls',
|
|
||||||
},
|
|
||||||
//
|
|
||||||
// Parse attrs...
|
|
||||||
// .parseBlockAttrs(<text>[, <elem>])
|
|
||||||
// -> <elem>
|
|
||||||
//
|
|
||||||
// Parse attrs keeping non-system attrs in .text...
|
|
||||||
// .parseBlockAttrs(<text>, true[, <elem>])
|
|
||||||
// -> <elem>
|
|
||||||
//
|
|
||||||
// Parse attrs keeping all attrs in .text...
|
|
||||||
// .parseBlockAttrs(<text>, 'all'[, <elem>])
|
|
||||||
// -> <elem>
|
|
||||||
//
|
|
||||||
// XXX move to config...
|
|
||||||
// XXX PLUGIN_ATTRS...
|
|
||||||
__code_attrs__: false,
|
|
||||||
parseBlockAttrs: function(text, keep=!!this.__code_attrs__, elem={}){
|
|
||||||
if(typeof(keep) == 'object'){
|
|
||||||
elem = keep
|
|
||||||
keep = typeof(elem) == 'boolean' ?
|
|
||||||
elem
|
|
||||||
: this.__code_attrs__ }
|
|
||||||
var system = this.__block_attrs__
|
|
||||||
var clean = text
|
|
||||||
// XXX for some reason changing the first group into (?<= .. )
|
|
||||||
// still eats up the whitespace...
|
|
||||||
// ...putting the same pattern in a normal group and
|
|
||||||
// returning it works fine...
|
|
||||||
//.replace(/(?<=[\n\h]*)(?:(?:\n|^)\s*\w*\s*::\s*[^\n]*\s*)*$/,
|
|
||||||
.replace(/([\n\t ]*)(?:(?:\n|^)[\t ]*\w+[\t ]*::[\t ]*[^\n]+[\t ]*)+$/,
|
|
||||||
function(match, ws){
|
|
||||||
var attrs = match
|
|
||||||
.trim()
|
|
||||||
.split(/(?:[\t ]*::[\t ]*|[\t ]*\n[\t ]*)/g)
|
|
||||||
while(attrs.length > 0){
|
|
||||||
var [name, val] = attrs.splice(0, 2)
|
|
||||||
elem[name] =
|
|
||||||
val == 'true' ?
|
|
||||||
true
|
|
||||||
: val == 'false' ?
|
|
||||||
false
|
|
||||||
: val
|
|
||||||
// keep non-system attrs...
|
|
||||||
if(keep
|
|
||||||
&& !(name in system)){
|
|
||||||
ws += `\n${name}::${val}` } }
|
|
||||||
return ws })
|
|
||||||
elem.text = keep == 'all' ?
|
|
||||||
text
|
|
||||||
: clean
|
|
||||||
return elem },
|
|
||||||
parse: function(text){
|
parse: function(text){
|
||||||
var that = this
|
var that = this
|
||||||
text = text
|
text = text
|
||||||
@ -1184,16 +1133,12 @@ var JSONOutline = {
|
|||||||
// same level...
|
// same level...
|
||||||
if(sep.length == prev_sep.length){
|
if(sep.length == prev_sep.length){
|
||||||
var [_, block] = lst.splice(0, 2)
|
var [_, block] = lst.splice(0, 2)
|
||||||
// XXX PLUGIN_ATTRS...
|
var attrs = {}
|
||||||
if(PLUGIN_ATTRS){
|
attrs.text = that.__text2code__(
|
||||||
var attrs = {}
|
that.threadPlugins('__parse_code__', block, that, attrs)
|
||||||
attrs.text = that.threadPlugins('__parse_code__', block, that, attrs)
|
// normalize indent...
|
||||||
} else {
|
.split(new RegExp('\n'+sep+' ', 'g'))
|
||||||
var attrs = that.parseBlockAttrs(block) }
|
.join('\n'))
|
||||||
attrs.text = that.__text2code__(attrs.text
|
|
||||||
// normalize indent...
|
|
||||||
.split(new RegExp('\n'+sep+' ', 'g'))
|
|
||||||
.join('\n'))
|
|
||||||
parent.push({
|
parent.push({
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
focused: false,
|
focused: false,
|
||||||
@ -1625,12 +1570,6 @@ var Outline = {
|
|||||||
that.change_interval || 1000)
|
that.change_interval || 1000)
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
__block_attrs__: {
|
|
||||||
id: 'attr',
|
|
||||||
collapsed: 'attr',
|
|
||||||
focused: 'cls',
|
|
||||||
},
|
|
||||||
|
|
||||||
/* XXX not used -- do we need this??
|
/* XXX not used -- do we need this??
|
||||||
// XXX UPDATE_CODE_SIZE this is a no-op at this point -- do we need this???
|
// XXX UPDATE_CODE_SIZE this is a no-op at this point -- do we need this???
|
||||||
_updateCodeSize: function(code, view){
|
_updateCodeSize: function(code, view){
|
||||||
@ -2726,17 +2665,10 @@ var Outline = {
|
|||||||
if(elem.classList.contains('code')){
|
if(elem.classList.contains('code')){
|
||||||
var block = that.get(elem)
|
var block = that.get(elem)
|
||||||
// clean out attrs...
|
// clean out attrs...
|
||||||
// XXX PLUGIN_ATTRS...
|
elem.value =
|
||||||
if(PLUGIN_ATTRS){
|
that.trim_block_text ?
|
||||||
elem.value =
|
that.threadPlugins('__parse_code__', elem.value, that).trim()
|
||||||
that.trim_block_text ?
|
: that.threadPlugins('__parse_code__', elem.value, that)
|
||||||
that.threadPlugins('__parse_code__', elem.value, that).trim()
|
|
||||||
: that.threadPlugins('__parse_code__', elem.value, that)
|
|
||||||
} else {
|
|
||||||
elem.value =
|
|
||||||
that.trim_block_text ?
|
|
||||||
that.parseBlockAttrs(elem.value).text.trim()
|
|
||||||
: that.parseBlockAttrs(elem.value).text }
|
|
||||||
that.update(block)
|
that.update(block)
|
||||||
// undo...
|
// undo...
|
||||||
if(elem.value != elem.dataset.original){
|
if(elem.value != elem.dataset.original){
|
||||||
|
|||||||
@ -145,18 +145,10 @@ var setup = function(){
|
|||||||
- ## ToDo:
|
- ## ToDo:
|
||||||
- attributes: need to show/hide the attributes -- option?
|
- attributes: need to show/hide the attributes -- option?
|
||||||
attr::value
|
attr::value
|
||||||
- Q: should this be completely handled by a plugin???
|
- `.__parse_code__(..)`: add data attributes to code if missing...
|
||||||
_(see: `PLUGIN_ATTRS`)_
|
|
||||||
- this plugin needs to be called from `JSONOutline` (???)
|
|
||||||
- `.parseBlockAttrs(..)`: add hook to plugins to handle output...
|
|
||||||
- _plugin will need to get the call context -- can be called when handling for view or code_
|
|
||||||
- `.parseBlockAttrs(..)`: add data attributes to code if missing...
|
|
||||||
- do we need `.__code_attrs__` / `.__view_attrs__`???
|
- do we need `.__code_attrs__` / `.__view_attrs__`???
|
||||||
- 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??
|
||||||
- might be a good idea to render plugins in a separate block shown with code...
|
|
||||||
- _when attr added to code -> transfer to attrs block..._
|
|
||||||
- this will help with caret transfer to be more predictable...
|
|
||||||
- TOC: tweaking: add args like depth, ... -- as attributes...
|
- TOC: tweaking: add args like depth, ... -- as attributes...
|
||||||
- TOC: should it be persistently generated as code and be serializable?
|
- TOC: should it be persistently generated as code and be serializable?
|
||||||
- ASAP: expand sub-tree on follow link...
|
- ASAP: expand sub-tree on follow link...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user