')
- .append($('')
- .html($(elem).html())) },
+ html: function(context, elem){
+ return $(elem) },
+ text: function(context, elem){
+ return $('')
+ .append($('')
+ .html($(elem).html())) },
// XXX expperimental...
json: function(context, elem){ return $('')
.html($(elem).text()
@@ -359,7 +339,10 @@ module = {
// XXX
nl2br: function(context, elem){
- return $('').html($(elem).html().replace(/\n/g, '
\n')) },
+ return $('
')
+ .html($(elem)
+ .html()
+ .replace(/\n/g, '
\n')) },
wikiword: function(context, elem){
return $('
')
@@ -396,8 +379,7 @@ module = {
.parent()
.addClass('checked')
.end()
- .end()
- },
+ .end() },
},
@@ -414,8 +396,7 @@ module = {
post_filter: {
noscript: function(context, elem){
// XXX
- return elem
- },
+ return elem },
// Setup the page title and .title element...
//
@@ -432,11 +413,9 @@ module = {
// show first H1 as title...
if(elem.find('.text').text().trim().indexOf(title.text().trim()) == 0){
title.detach()
- elem.find('.title').html(title.html())
- }
+ elem.find('.title').html(title.html()) }
- return elem
- },
+ return elem },
// XXX this needs save/reload...
editor: function(context, elem){
// XXX title
@@ -445,8 +424,7 @@ module = {
// XXX raw
// XXX checkbox
- return elem
- },
+ return elem },
},
@@ -485,7 +463,8 @@ module = {
state.seen = state.seen || []
//pattern = pattern || RegExp('@([a-zA-Z-_]+)\\(([^)]*)\\)', 'mg')
- pattern = pattern || RegExp.apply(null, this.__macro__pattern__)
+ pattern = pattern
+ || RegExp.apply(null, this.__macro__pattern__)
// XXX need to quote regexp chars...
var include_marker = RegExp(this.__include_marker__, 'g')
@@ -498,9 +477,8 @@ module = {
return text.replace(pattern, function(match){
// quoted macro...
if(match[0] == '\\' && macro['*'] == null){
- return match.slice(1)
- //return match
- }
+ return match.slice(1) }
+ //return match }
// XXX parse match...
var d = match.match(/@([a-zA-Z-_:]*)\(([^)]*)\)/)
@@ -510,22 +488,30 @@ module = {
if(name in macro || '*' in macro){
var elem = $('<'+name+'/>')
- name = name in macro ? name : '*'
+ name = name in macro ?
+ name
+ : '*'
// format positional args....
var a = d[2]
.split(/((['"]).*?\2)|\s+/g)
// cleanup...
- .filter(function(e){ return e && e != '' && !/^['"]$/.test(e)})
+ .filter(function(e){
+ return e
+ && e != ''
+ && !/^['"]$/.test(e)})
// remove quotes...
- .map(function(e){ return /^(['"]).*\1$/.test(e) ? e.slice(1, -1) : e })
+ .map(function(e){
+ return /^(['"]).*\1$/.test(e) ?
+ e.slice(1, -1)
+ : e })
// add the attrs to the element...
name != '*'
&& a.forEach(function(e, i){
var k = ((macro[name] || {}).macro_args || [])[i]
- k && elem.attr(k, e)
- })
+ k
+ && elem.attr(k, e) })
// call macro...
var res = macro[name]
@@ -539,35 +525,29 @@ module = {
res.map(function(i, e){ return e.outerHTML })
.toArray()
.join('\n')
- : typeof(res) != typeof('str') ? res.outerHTML
- : res
- }
+ : typeof(res) != typeof('str') ?
+ res.outerHTML
+ : res }
- return match
- })
- }
+ return match }) }
// NOTE: this modifies parsed in-place...
var _parse = function(context, parsed, macro){
$(parsed).contents().each(function(_, e){
// #text / comment node -> parse the @... macros...
- if(e.nodeType == e.TEXT_NODE || e.nodeType == e.COMMENT_NODE){
+ if(e.nodeType == e.TEXT_NODE
+ || e.nodeType == e.COMMENT_NODE){
// get actual element content...
- var text = e.nodeValue
+ // NOTE: we need to do this like this to avoid
+ // unparsing special characters...
+ var text = $('').append($(e).clone()).html()
// conditional comment...
- if(e.nodeType == e.COMMENT_NODE){
- text = /^$/.test(text) ?
- text
- .replace(/^$/, '')
- : ('')
- }
+ if(e.nodeType == e.COMMENT_NODE
+ && /^$/.test(text)){
+ text = text
+ .replace(/^$/, '') }
- /*
- var t = _parseText(context, text, macro)
- text != t
- && $(e).replaceWith(t)
- //*/
$(e).replaceWith(_parseText(context, text, macro))
// node -> html-style + attrs...
@@ -578,8 +558,7 @@ module = {
for(var i=0; i < e.attributes.length; i++){
var attr = e.attributes[i]
- attr.value = _parseText(context, attr.value, macro)
- }
+ attr.value = _parseText(context, attr.value, macro) }
// macro match -> call macro...
if(name in macro){
@@ -590,13 +569,9 @@ module = {
// normal tag -> sub-tree...
} else {
- _parse(context, e, macro)
- }
- }
- })
+ _parse(context, e, macro) } } })
- return parsed
- }
+ return parsed }
var _filter = function(lst, filters){
lst
// unique -- leave last occurance..
@@ -605,8 +580,7 @@ module = {
// filter dupplicates...
&& lst.slice(i+1).indexOf(k) == -1
// filter disabled...
- && lst.slice(0, i).indexOf('-' + k) == -1
- })
+ && lst.slice(0, i).indexOf('-' + k) == -1 })
// unique -- leave first occurance..
//.filter(function(k, i, lst){ return lst.slice(0, i).indexOf(k) == -1 })
// apply the filters...
@@ -616,17 +590,13 @@ module = {
var seen = []
while(typeof(k) == typeof('str') && seen.indexOf(k) == -1){
seen.push(k)
- k = filters[k]
- }
+ k = filters[k] }
// could not find the filter...
if(!k){
//console.warn('Unknown filter:', f)
- return
- }
+ return }
// use the filter...
- parsed = k.call(that, context, parsed)
- })
- }
+ parsed = k.call(that, context, parsed) }) }
// macro stage...
_parse(context, parsed, this.macro)
@@ -649,8 +619,7 @@ module = {
var seen = state.seen.slice()
if(seen.indexOf(page.path()) >= 0){
- return elem.html()
- }
+ return elem.html() }
seen.push(page.path())
return page.map(function(page){
@@ -669,11 +638,10 @@ module = {
!isolated)))
//true)))
.html()
- }).join('\n')
- }))
+ }).join('\n') }))
// XXX DEBUG...
- console.log('<<<', context.path(),'TIME:', Date.now() - t)
+ //console.log('<<<', context.path(),'TIME:', Date.now() - t)
// post processing...
if(!skip_post){
@@ -690,15 +658,14 @@ module = {
// ...check if it prevents correct slot parsing
// within an isolated include...
if(e.parents('[isolated="true"]').length > 0){
- return
- }
+ return }
var n = e.attr('name')
- n in slots && e.detach()
+ n in slots
+ && e.detach()
- slots[n] = e
- })
+ slots[n] = e })
// place slots...
parsed.find('slot')
.each(function(i, e){
@@ -708,13 +675,11 @@ module = {
// ...check if it prevents correct slot parsing
// within an isolated include...
if(e.parents('[isolated="true"]').length > 0){
- return
- }
+ return }
var n = e.attr('name')
- e.replaceWith(slots[n])
- })
+ e.replaceWith(slots[n]) })
// post-macro...
// XXX for some odd reason this clears the backslash from
@@ -728,8 +693,7 @@ module = {
_filter(this.__post_filters__, this.post_filter)
// XXX shuld we get rid of the root span???
- return parsed.contents()
- },
+ return parsed.contents() },
}
diff --git a/pwiki.js b/pwiki.js
index 45e8dda..a943cf8 100755
--- a/pwiki.js
+++ b/pwiki.js
@@ -184,9 +184,11 @@ module.BaseData = {
// Page modifiers/actions...
// XXX these needs redirecting...
- //'System/sort': function(){ return this.get('..').sort() },
- //'System/reverse': function(){ return this.get('..').reverse() },
- /*
+ 'System/sort': function(){
+ return this.get('..').sort() },
+ 'System/reverse': function(){
+ return this.get('..').reverse() },
+
'System/delete': function(){
var p = this.dir
delete this.__wiki_data[p]
@@ -422,7 +424,8 @@ module.pWikiBase = actions.Actions({
// XXX should this be local/dump???
- json: ['', function(){ }],
+ json: ['',
+ function(){ }],
// Location and path API...
@@ -1056,7 +1059,6 @@ module.pWikiMacros = actions.Actions(pWikiBase, {
// parse macros...
: (this.__macro_parser__ || pWikiMacros.__macro_parser__)
.parse(this, this.raw()))
-
// set...
: this
// clear cached stuff related to text...
@@ -1274,13 +1276,16 @@ var pWikiLocalStorage = pWikiFeatures.Feature({
'update',
'clear',
],
- function(){ this.save() }],
+ function(){
+ this.save() }],
[[
'path',
'data',
],
- function(){ arguments.length > 1 && this.save() }],
+ function(){
+ arguments.length > 1
+ && this.save() }],
],
})
@@ -1372,10 +1377,7 @@ var pWikiUIActions = actions.Actions({
client.reload() })
- /* XXX this messes up history for some reason...
- $('title').text(elems.first().text())
- //*/
- },
+ $('title').text(elems.first().text()) },
// raw text editor...
'.raw': function(elems){
var client = this
@@ -1468,8 +1470,7 @@ var pWikiUIActions = actions.Actions({
(this.dom
.find('#'+hash+', a[name="'+hash+'"]').first()
.offset() || {}).top || 0)
- && console.log('HASH:', hash)
- }],
+ && console.log('HASH:', hash) }],
reload: ['',
function(){
var that = this