diff --git a/wiki.js b/wiki.js
index b348779..0c25123 100755
--- a/wiki.js
+++ b/wiki.js
@@ -93,7 +93,20 @@ var macro = {
//
// XXX should inline macros support named args???
__macro__pattern__:
- /<([a-zA-Z-_:]+)(.|[\n\r])*?(>(.|[\n\r])*?<\/\1>|\/>)|@([a-zA-Z-_]+)\(([^)]*)\)/mg,
+ ///<([a-zA-Z-_:]+)(.|[\n\r])*?(>(.|[\n\r])*?<\/\1>|\/>)|@([a-zA-Z-_]+)\(([^)]*)\)/mg,
+ [[
+ //
+ // text
+ '<([a-zA-Z-_:]+)(.|[\\n\\r])*?(>(.|[\\n\\r])*?<\\/\\1>|\\/>)',
+ /*// same as above but HTML-level...
+ '<([a-zA-Z-_:]+)(.|[\\n\\r])*?(>(.|[\\n\\r])*?<\\/\\1>|\\/>)'
+ .replace(//g, '\\>'),
+ //*/
+
+ // @macro(arg ..)
+ '@([a-zA-Z-_]+)\\(([^)]*)\\)'
+ ].join('|'), 'mg'],
// default filters...
//
@@ -157,11 +170,14 @@ var macro = {
}),
// fill/define slot (stage 1)...
+ //
+ // XXX which should have priority the arg text or the content???
slot: Macro('Define/fill slot',
- ['name'],
+ ['name', 'text'],
function(context, args, text, state){
var name = args.name
+ //text = text || args.text
text = this.parse(context, text, state, true)
if(state.slots[name] == null){
@@ -225,6 +241,7 @@ var macro = {
// NOTE: slots are parsed in the context of their containing page
// and not in the location they are being placed.
//
+ // XXX support quoted text...
parseElem: function(text, stage){
var res = {}
@@ -236,11 +253,23 @@ var macro = {
res.name = d[1]
var args = res.args = {}
- var a = d[2].split(/\s+/g)
+ // XXX support escaped quotes...
+ //var a = d[2].split(/\s+/g)
+ var a = d[2]
+ .split(/((['"]).*?\2)|\s+/g)
+ // cleanup...
+ .filter(function(e){ return e && e != '' && !/^['"]$/.test(e)})
+ // remove quotes...
+ .map(function(e){ return /^(['"]).*\1$/.test(e) ? e.slice(1, -1) : e })
+
a.forEach(function(e, i){
- args[((stage[res.name] || {}).macro_args || [])[i]] = e
+ args[((stage[res.name] || {}).macro_args || [])[i] || i] = e
})
+ if(args.text){
+ res.text = args.text
+ }
+
// html-like...
} else {
var elem = res.elem = $('
').html(text).children().eq(0)
@@ -258,16 +287,21 @@ var macro = {
return res
},
- parse: function(context, text, state, skip_post){
+ // XXX need to parse argument value content for macros...
+ // XXX try and avoid parsing HTML by hand...
+ parse: function(context, text, state, skip_post, pattern){
var that = this
+
state = state || {}
state.filters = state.filters || []
state.slots = state.slots || {}
state.include = state.include || []
+ pattern = pattern || RegExp.apply(null, this.__macro__pattern__)
+ // XXX need to parse argument value content for macros...
var _parse = function(context, text, macro){
- return text.replace(that.__macro__pattern__, function(match){
+ return text.replace(pattern, function(match){
var m = that.parseElem(match, macro)
// found a macro...
@@ -459,9 +493,12 @@ var data = {
text: '\n'
+'\n'
+'\n'
- +'
/@include(../path) (
edit)
\n'
+ +'
\n'
+'
\n'
- +'
@include(../title)
\n'
+ //+'
@include(../title)
\n'
+ +'
'
+ +'@include(../title)'
+ +'
\n'
+'
\n'
+'
@include(..)
\n'
+'
\n'
@@ -472,7 +509,7 @@ var data = {
text: '\n'
+'\n'
+'\n'
- +'
/@include(../path) (
view)
\n'
+ +'
\n'
+'
\n'
+'
@include(../title)
\n'
+'
\n'