Compare commits

..

No commits in common. "70560eb437818ef45899454695b82a9cb07c514e" and "3d8caaafb4daeefd4b3048109d7ee0c1409c2de8" have entirely different histories.

2 changed files with 111 additions and 46 deletions

View File

@ -5,6 +5,10 @@
**********************************************************************/
// XXX
var PLUGIN_ATTRS = true
//---------------------------------------------------------------------
// Helpers...
@ -193,29 +197,10 @@ var plugin = {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Process attributes in code and update the attributes in element data...
//
// This does:
// - parse attributes
// - update element data (JSON)
// - filter attributes out (optionally)
//
// XXX PLUGIN_ATTRS
var attributes = {
__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__???
// ...editor (current), plugin, ...???
// XXX might be a good idea to split out the actual code handler to
@ -653,7 +638,6 @@ var tasks = {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX add depth...
// XXX do a better default id...
var toc = {
__proto__: plugin,
@ -902,15 +886,6 @@ var escaping = {
//---------------------------------------------------------------------
var JSONOutline = {
__code_attrs__: false,
__view_attrs__: false,
__block_attrs__: {
id: 'attr',
collapsed: 'attr',
focused: 'cls',
},
// Plugins...
//
// The order of plugins can be significant in the following cases:
@ -923,7 +898,11 @@ var JSONOutline = {
//
// XXX split out DOM-specific plugins into Outline.plugins...
pre_plugins: [
attributes,
// XXX PLUGIN_ATTRS
...(PLUGIN_ATTRS ?
[attributes]
: []),
//*/
blocks,
quoted,
],
@ -1051,12 +1030,13 @@ var JSONOutline = {
// .__post_parse__(..)
//
// XXX PRE_POST_NEWLINE can we avoid explicitly patching for empty lines after pre???
__view_attrs__: false,
__code2html__: function(code, elem={}){
var that = this
// only whitespace -> keep element blank...
elem.text = code
if(code.trim() == ''){
elem.text = code
return elem }
// helpers...
@ -1068,6 +1048,13 @@ var JSONOutline = {
}[stage]
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...
var text = run('pre',
// pre-sanitize...
@ -1122,6 +1109,62 @@ var JSONOutline = {
text.trim()
: 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){
var that = this
text = text
@ -1141,12 +1184,16 @@ var JSONOutline = {
// same level...
if(sep.length == prev_sep.length){
var [_, block] = lst.splice(0, 2)
var attrs = {}
attrs.text = that.__text2code__(
that.threadPlugins('__parse_code__', block, that, attrs)
// normalize indent...
.split(new RegExp('\n'+sep+' ', 'g'))
.join('\n'))
// XXX PLUGIN_ATTRS...
if(PLUGIN_ATTRS){
var attrs = {}
attrs.text = that.threadPlugins('__parse_code__', block, that, attrs)
} else {
var attrs = that.parseBlockAttrs(block) }
attrs.text = that.__text2code__(attrs.text
// normalize indent...
.split(new RegExp('\n'+sep+' ', 'g'))
.join('\n'))
parent.push({
collapsed: false,
focused: false,
@ -1578,6 +1625,12 @@ var Outline = {
that.change_interval || 1000)
return this },
__block_attrs__: {
id: 'attr',
collapsed: 'attr',
focused: 'cls',
},
/* XXX not used -- do we need this??
// XXX UPDATE_CODE_SIZE this is a no-op at this point -- do we need this???
_updateCodeSize: function(code, view){
@ -2673,10 +2726,17 @@ var Outline = {
if(elem.classList.contains('code')){
var block = that.get(elem)
// clean out attrs...
elem.value =
that.trim_block_text ?
that.threadPlugins('__parse_code__', elem.value, that).trim()
: that.threadPlugins('__parse_code__', elem.value, that)
// XXX PLUGIN_ATTRS...
if(PLUGIN_ATTRS){
elem.value =
that.trim_block_text ?
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)
// undo...
if(elem.value != elem.dataset.original){

View File

@ -145,16 +145,21 @@ var setup = function(){
- ## ToDo:
- attributes: need to show/hide the attributes -- option?
attr::value
- `.__parse_code__(..)`: add data attributes to code if missing...
- Q: should this be completely handled by a plugin???
_(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__`???
- handle attr delete correctly -- i.e. if shown attr removed from code -> delete attr...
- 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: should it be persistently generated as code and be serializable?
- ASAP: expand sub-tree on follow link...
- simple use strategies:
- custom element
- constructor
- export auto-headings as normal/manual markdown headings...
- add plugin callback on `.text(..)` / ...
- Time to think about a standalone client -- at least to edit own notes as a test...