mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00:08 +00:00
experimenting with macros...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b8174abd5a
commit
2260f75e8c
68
index.html
68
index.html
@ -21,7 +21,57 @@ var reload = () => {
|
|||||||
|
|
||||||
$('.title').text(Wiki.title)
|
$('.title').text(Wiki.title)
|
||||||
|
|
||||||
$('.text').html(activateWikiWords(Wiki.text))
|
// process text...
|
||||||
|
var text = Wiki.text
|
||||||
|
|
||||||
|
// expand macros...
|
||||||
|
if($('.text').prop('contenteditable') != 'true'){
|
||||||
|
text = text
|
||||||
|
// Syntax:
|
||||||
|
// @<macro>( <args> )
|
||||||
|
.replace(/@([a-zA-Z-_]+)\(([^)]*)\)/g, function(_, macro, args){
|
||||||
|
args = $('<div>')
|
||||||
|
.html(args)
|
||||||
|
.text()
|
||||||
|
.trim()
|
||||||
|
.split(/\s+/g)
|
||||||
|
|
||||||
|
//console.log('>>>>>', macro, args)
|
||||||
|
|
||||||
|
if(macro == 'include' && args.length == 1){
|
||||||
|
w = Object.create(Wiki)
|
||||||
|
w.location = args[0]
|
||||||
|
return w.text
|
||||||
|
}
|
||||||
|
|
||||||
|
return _
|
||||||
|
})
|
||||||
|
// html-like macro syntax...
|
||||||
|
.replace(/\<[a-zA-Z-_:]+.*?\/?\>/g, function(t){
|
||||||
|
var elem = $($('<div>').html(t).text())
|
||||||
|
var macro = elem.prop('tagName').toLowerCase()
|
||||||
|
|
||||||
|
var args = {}
|
||||||
|
var a = elem.prop('attributes')
|
||||||
|
|
||||||
|
for(var i=0; i<a.length; i++){
|
||||||
|
args[a[i].name] = a[i].value
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log('>>>>>', macro, args)
|
||||||
|
|
||||||
|
if(macro == 'include' && args.src != null){
|
||||||
|
w = Object.create(Wiki)
|
||||||
|
w.location = args.src
|
||||||
|
return w.text
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return t
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.text').html(activateWikiWords(text))
|
||||||
|
|
||||||
// XXX save...
|
// XXX save...
|
||||||
localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
|
localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
|
||||||
@ -85,11 +135,21 @@ $(() => {
|
|||||||
// live update text...
|
// live update text...
|
||||||
// XXX is this the right way to go for large documents???
|
// XXX is this the right way to go for large documents???
|
||||||
$('.text')
|
$('.text')
|
||||||
|
.focus(() => {
|
||||||
|
$('.text').prop('contenteditable', $('.text').prop('contenteditable') != 'true')
|
||||||
|
reload()
|
||||||
|
})
|
||||||
.on('keyup', () => {
|
.on('keyup', () => {
|
||||||
Wiki.text = clearWikiWords($('.text').clone()).html() })
|
if($('.text').prop('contenteditable') == 'true'){
|
||||||
|
Wiki.text = clearWikiWords($('.text').clone()).html()
|
||||||
|
}
|
||||||
|
})
|
||||||
// XXX do this live, but on a timeout after user input...
|
// XXX do this live, but on a timeout after user input...
|
||||||
// XXX need to place the cursor in the same position...
|
// XXX need to place the cursor in the same position...
|
||||||
.blur(() => { reload() })
|
.blur(() => {
|
||||||
|
$('.text').prop('contenteditable', false)
|
||||||
|
reload()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -98,7 +158,7 @@ $(() => {
|
|||||||
<div class="dir"></div>
|
<div class="dir"></div>
|
||||||
<hr>
|
<hr>
|
||||||
<h1 class="title" contenteditable tabindex=0></h1>
|
<h1 class="title" contenteditable tabindex=0></h1>
|
||||||
<div class="text" contenteditable tabindex=0></div>
|
<div class="text" tabindex=0></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
9
wiki.js
9
wiki.js
@ -21,7 +21,8 @@ var BaseData = {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
.filter((e) => e != null)
|
.filter(e => e != null)
|
||||||
|
.map(e => '['+ e +']')
|
||||||
.join('<br>')
|
.join('<br>')
|
||||||
},
|
},
|
||||||
'Templates/tree': function(){
|
'Templates/tree': function(){
|
||||||
@ -34,7 +35,8 @@ var BaseData = {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
.filter((e) => e != null)
|
.filter(e => e != null)
|
||||||
|
.map(e => '['+ e +']')
|
||||||
.join('<br>')
|
.join('<br>')
|
||||||
},
|
},
|
||||||
'Templates/links': function(){
|
'Templates/links': function(){
|
||||||
@ -53,7 +55,8 @@ var BaseData = {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
.map(e => '['+ e[0] +'] <i>from page: '+ e[1] +'</i>')
|
//.map(e => '['+ e[0] +'] <i>from page: ['+ e[1] +']</i>')
|
||||||
|
.map(e => '['+ e[1] +'] <i>-> ['+ e[0] +']</i>')
|
||||||
.join('<br>')
|
.join('<br>')
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user