added experimental JSON page / .code support...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-07-27 02:13:15 +03:00
parent b167af0f51
commit da7a1f446f

60
wiki.js
View File

@ -207,14 +207,19 @@ var macro = {
// Signature: // Signature:
// filter(text) -> html // filter(text) -> html
// //
// XXX
filter: { filter: {
default: 'html', default: 'html',
html: function(context, elem){ return $(elem) }, html: function(context, elem){ return $(elem) },
json: 'text', text: function(context, elem){ return $('<span>')
text: function(context, elem){ return $('<div>').html($(elem).text()) }, .append($('<pre>')
.html($(elem).html())) },
// XXX expperimental...
json: function(context, elem){ return $('<span>')
.html($(elem).text()
// remove JS comments...
.replace(/\s*\/\/.*$|\s*\/\*(.|[\n\r])*?\*\/\s*/mg, '')) },
// XXX // XXX
//nl2br: function(context, text){ return $('<div>').html(text.replace(/\n/g, '<br>\n')) }, //nl2br: function(context, text){ return $('<div>').html(text.replace(/\n/g, '<br>\n')) },
@ -240,9 +245,7 @@ var macro = {
// and not in the location they are being placed. // and not in the location they are being placed.
// //
// XXX support quoted text... // XXX support quoted text...
// XXX this expect a different macro signature: // XXX need to quote regexp chars of .__include_marker__...
// macro(context, element, state)
// -> text
parse: function(context, text, state, skip_post, pattern){ parse: function(context, text, state, skip_post, pattern){
var that = this var that = this
@ -264,7 +267,7 @@ var macro = {
var _parseText = function(context, text, macro){ var _parseText = function(context, text, macro){
return text.replace(pattern, function(match){ return text.replace(pattern, function(match){
// XXX parse match... // XXX parse match...
var d = text.match(/@([a-zA-Z-_:]*)\(([^)]*)\)/) var d = match.match(/@([a-zA-Z-_:]*)\(([^)]*)\)/)
var name = d[1] var name = d[1]
@ -501,20 +504,6 @@ var data = {
+'\n', +'\n',
}, },
ParserTestPage: {
text: '<div>\n'
+'<h2>nested single line element</h2>\n'
// This breaks the parser on the post-macro stage...
+'<h3><span>\n'
+'nested multi-line</span> element\n'
+'</h3>\n'
// this will get completely messed up by the parser...
+'<span> abc <span> 123 </span> xyz </span>'
+'</div>'
},
'Templates/_raw': { 'Templates/_raw': {
text: '@source(..)', text: '@source(..)',
}, },
@ -524,7 +513,10 @@ var data = {
+'\n' +'\n'
+'<div>@include(../path) (<a href="#./_edit">edit</a>)</div>\n' +'<div>@include(../path) (<a href="#./_edit">edit</a>)</div>\n'
+'<hr>\n' +'<hr>\n'
+'<h1 class="title" contenteditable tabindex="0">@include(../title)</h1>\n' +'<h1 class="title" contenteditable tabindex="0">'
//+'<slot name="title">@include(../title)</slot>'
+'@include(../title)'
+'</h1>\n'
+'<br>\n' +'<br>\n'
+'<div class="text" tabindex="0"> @include(..) </div>\n' +'<div class="text" tabindex="0"> @include(..) </div>\n'
+'<hr>\n' +'<hr>\n'
@ -557,15 +549,20 @@ data.__proto__ = BaseData
var Wiki = { var Wiki = {
__wiki_data: data, __wiki_data: data,
__config_page__: 'System/config', __config_page__: 'System/Settings',
__home_page__: 'WikiHome', __home_page__: 'WikiHome',
__default_page__: 'EmptyPage', __default_page__: 'EmptyPage',
// Special sub-paths to look in on each level... // Special sub-paths to look in on each level...
__acquesition_order__: [ __acquesition_order__: [
'Templates', 'Templates',
], ],
__post_acquesition_order__: [ __post_acquesition_order__: [
], ],
// XXX should this be read only??? // XXX should this be read only???
__system__: 'System', __system__: 'System',
//__redirect_template__: 'RedirectTemplate', //__redirect_template__: 'RedirectTemplate',
@ -607,12 +604,9 @@ var Wiki = {
get data(){ get data(){
return this.__wiki_data[this.acquire()] }, return this.__wiki_data[this.acquire()] },
/* // XXX experimental...
// XXX
get config(){ get config(){
return this.__wiki_data[this.__config_page__] || {} return JSON.parse(this.get(this.__config_page__).code) || {} },
},
//*/
// XXX // XXX
@ -791,13 +785,13 @@ var Wiki = {
}, },
parse: function(state, skip_post){ get text(){
//return this.parse()
// special case: if we are getting ./raw then do not parse text... // special case: if we are getting ./raw then do not parse text...
return this.title == 'raw' ? this.raw return this.title == 'raw' ? this.raw
: this.__macro_parser__.parse(this, this.raw, state, skip_post) : this.__macro_parser__.parse(this, this.raw) },
}, get code(){
get text(){ return this.text.html() },
return this.parse() },
// NOTE: this is set by setting .text // NOTE: this is set by setting .text