From 71a88308005aebaa67f83cfaad2f24e448082915 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 15 Aug 2016 17:36:33 +0300 Subject: [PATCH] added macro quoting + readme... Signed-off-by: Alex A. Naanou --- README.md | 22 ++++++++++++++++++++-- make_bootstrap.js | 6 ++++++ wiki.js | 43 ++++++++++++++++++++++++++++++++----------- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 33f3552..332d36a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -# pWiki -Portable Wiki +# Portable Wiki (pWiki) + +Project goals: +- Provide a simple embeddable Wiki + This enables a zero-workflow app documentation, i.e. documentation that + can be created, edited, tweaked and updated in-app without requiring + setting up and maintaining a write-convert-embed workflow. + +- Provide pluggable storage and synchronization + +- Implement a Wiki/note _portable_ app + - a simple and functional note/todo/outline app + - an external/portable Wiki editor, as an alternative for in-app + documentation editor with ability to seamlesly synchronize with + the target app. + - a stand-alone testing platform for project components + +General Documentation: +- WikiPath +- WikiMacros / [bootstrap/WikiMacros.tpl] diff --git a/make_bootstrap.js b/make_bootstrap.js index 45230d9..04c8675 100644 --- a/make_bootstrap.js +++ b/make_bootstrap.js @@ -31,6 +31,12 @@ glob('bootstrap/**/*.tpl') +'\n\n' +'var Bootstrap = ' + JSON.stringify(bootstrap) + if(!bootstrap.WikiHome && fs.existsSync('README.md')){ + bootstrap.WikiHome = { + text: fs.readFileSync('README.md').toString(), + } + } + console.log('Writing:', 'bootstrap.js') fs.writeFileSync('bootstrap.js', txt) }) diff --git a/wiki.js b/wiki.js index ba2988e..2ee8a9e 100755 --- a/wiki.js +++ b/wiki.js @@ -102,7 +102,7 @@ var macro = { __macro__pattern__: [[ // @macro(arg ..) - '@([a-zA-Z-_]+)\\(([^)]*)\\)' + '\\\\?@([a-zA-Z-_]+)\\(([^)]*)\\)' ].join('|'), 'mg'], // default filters... @@ -289,7 +289,16 @@ var macro = { // Post macros... // + // XXX this is disabled for now, see end of .parse(..) post_macro: { + '*': Macro('cleanup...', + [], + function(context, elem, state, parse, match){ + if(match != null){ + return match[0] == '\\' ? match.slice(1) : match + } + return elem + }), /* _slot: Macro('', ['name'], @@ -432,14 +441,22 @@ var macro = { var _parseText = function(context, text, macro){ return text.replace(pattern, function(match){ + // quoted macro... + if(match[0] == '\\' && macro['*'] == null){ + return match.slice(1) + //return match + } + // XXX parse match... var d = match.match(/@([a-zA-Z-_:]*)\(([^)]*)\)/) var name = d[1] - if(name in macro){ + if(name in macro || '*' in macro){ var elem = $('<'+name+'/>') + name = name in macro ? name : '*' + // format positional args.... var a = d[2] .split(/((['"]).*?\2)|\s+/g) @@ -449,16 +466,18 @@ var macro = { .map(function(e){ return /^(['"]).*\1$/.test(e) ? e.slice(1, -1) : e }) // add the attrs to the element... - a.forEach(function(e, i){ - var k = ((macro[name] || {}).macro_args || [])[i] - k && elem.attr(k, e) - }) + name != '*' + && a.forEach(function(e, i){ + var k = ((macro[name] || {}).macro_args || [])[i] + k && elem.attr(k, e) + }) // call macro... var res = macro[name] .call(that, context, elem, state, function(elem, c){ - return _parse(c || context, elem, macro) }) + return _parse(c || context, elem, macro) }, + match) return res instanceof jQuery ? // merge html of the returned set of elements... @@ -602,12 +621,14 @@ var macro = { }) // post-macro... - this.post_macro - && _parse(context, parsed, this.post_macro) + // XXX for some odd reason this clears the backslash from + // quoted macros in raw fields... + //this.post_macro + // && _parse(context, parsed, this.post_macro) } - // XXX shuld we get rid of the rot span??? - return parsed + // XXX shuld we get rid of the root span??? + return parsed.contents() }, }