From da7a1f446f92cfea777b49415afe33abd9f2e2c8 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 27 Jul 2016 02:13:15 +0300 Subject: [PATCH] added experimental JSON page / .code support... Signed-off-by: Alex A. Naanou --- wiki.js | 60 ++++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/wiki.js b/wiki.js index 59285de..3e7d907 100755 --- a/wiki.js +++ b/wiki.js @@ -207,14 +207,19 @@ var macro = { // Signature: // filter(text) -> html // - // XXX filter: { default: 'html', html: function(context, elem){ return $(elem) }, - json: 'text', - text: function(context, elem){ return $('
').html($(elem).text()) }, + text: function(context, elem){ return $('') + .append($('
')
+				.html($(elem).html())) },
+		// XXX expperimental...
+		json: function(context, elem){ return $('')
+			.html($(elem).text()
+				// remove JS comments...
+				.replace(/\s*\/\/.*$|\s*\/\*(.|[\n\r])*?\*\/\s*/mg, '')) },
 
 		// XXX
 		//nl2br: function(context, text){ return $('
').html(text.replace(/\n/g, '
\n')) }, @@ -240,9 +245,7 @@ var macro = { // and not in the location they are being placed. // // XXX support quoted text... - // XXX this expect a different macro signature: - // macro(context, element, state) - // -> text + // XXX need to quote regexp chars of .__include_marker__... parse: function(context, text, state, skip_post, pattern){ var that = this @@ -264,7 +267,7 @@ var macro = { var _parseText = function(context, text, macro){ return text.replace(pattern, function(match){ // XXX parse match... - var d = text.match(/@([a-zA-Z-_:]*)\(([^)]*)\)/) + var d = match.match(/@([a-zA-Z-_:]*)\(([^)]*)\)/) var name = d[1] @@ -501,20 +504,6 @@ var data = { +'\n', }, - ParserTestPage: { - text: '
\n' - +'

nested single line element

\n' - - // This breaks the parser on the post-macro stage... - +'

\n' - +'nested multi-line element\n' - +'

\n' - - // this will get completely messed up by the parser... - +' abc 123 xyz ' - +'
' - }, - 'Templates/_raw': { text: '@source(..)', }, @@ -524,7 +513,10 @@ var data = { +'\n' +'
@include(../path) (edit)
\n' +'
\n' - +'

@include(../title)

\n' + +'

' + //+'@include(../title)' + +'@include(../title)' + +'

\n' +'
\n' +'
@include(..)
\n' +'
\n' @@ -557,15 +549,20 @@ data.__proto__ = BaseData var Wiki = { __wiki_data: data, - __config_page__: 'System/config', + __config_page__: 'System/Settings', + __home_page__: 'WikiHome', + __default_page__: 'EmptyPage', + // Special sub-paths to look in on each level... __acquesition_order__: [ 'Templates', ], + __post_acquesition_order__: [ ], + // XXX should this be read only??? __system__: 'System', //__redirect_template__: 'RedirectTemplate', @@ -607,12 +604,9 @@ var Wiki = { get data(){ return this.__wiki_data[this.acquire()] }, - /* - // XXX + // XXX experimental... get config(){ - return this.__wiki_data[this.__config_page__] || {} - }, - //*/ + return JSON.parse(this.get(this.__config_page__).code) || {} }, // 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... return this.title == 'raw' ? this.raw - : this.__macro_parser__.parse(this, this.raw, state, skip_post) - }, - get text(){ - return this.parse() }, + : this.__macro_parser__.parse(this, this.raw) }, + get code(){ + return this.text.html() }, // NOTE: this is set by setting .text