mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-16 16:11:39 +00:00
make wikiwords passive...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
2992634e54
commit
0e4703b1b3
118
index.html
118
index.html
@ -8,6 +8,7 @@
|
||||
|
||||
<script src="ext-lib/jquery.js"></script>
|
||||
<script src="ext-lib/pouchdb.min.js"></script>
|
||||
<script src="ext-lib/peer.min.js"></script>
|
||||
<script src="wiki.js"></script>
|
||||
|
||||
<script>
|
||||
@ -17,112 +18,10 @@ var clear = () => {
|
||||
delete localStorage['wiki-location']
|
||||
}
|
||||
|
||||
|
||||
|
||||
var reload = () => {
|
||||
|
||||
//*
|
||||
//$('.wiki').html(Wiki.text)
|
||||
//var editing = $('.text').prop('contenteditable') != 'false'
|
||||
|
||||
$('.wiki')
|
||||
.html(Wiki.get('./_view').text)
|
||||
//*/
|
||||
|
||||
/*
|
||||
$('.path').text('/' + Wiki.path)
|
||||
|
||||
$('.title').text(Wiki.title)
|
||||
|
||||
// process text...
|
||||
var text = Wiki.raw
|
||||
var editing = $('.text').prop('contenteditable') != 'true'
|
||||
var filters = []
|
||||
var slots = {}
|
||||
|
||||
// expand macros...
|
||||
if(editing){
|
||||
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 == 'filter' && args.length == 1){
|
||||
filters.push(args[0])
|
||||
return ''
|
||||
}
|
||||
|
||||
if(macro == 'include' && args.length == 1){
|
||||
w = Object.create(Wiki)
|
||||
w.location = args[0]
|
||||
return w.raw
|
||||
}
|
||||
|
||||
if(macro == 'attr'
|
||||
&& args.length == 1
|
||||
&& ['title', 'path', 'location', 'dir'].indexOf(args[0]) >= 0){
|
||||
return Wiki[args[0]]
|
||||
}
|
||||
|
||||
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 == 'filter' && args.name != null){
|
||||
console.log('FILTER:', args.name)
|
||||
// XXX
|
||||
return ''
|
||||
}
|
||||
|
||||
if(macro == 'include' && args.src != null){
|
||||
w = Object.create(Wiki)
|
||||
w.location = args.src
|
||||
return w.raw
|
||||
}
|
||||
|
||||
// XXX need content...
|
||||
// Procedure:
|
||||
// - if new slot
|
||||
// - add to list
|
||||
// - fill
|
||||
// - if slot exists
|
||||
// - fill original
|
||||
if(macro == 'slot' && args.name != null){
|
||||
slots[args.name] = ''
|
||||
return t
|
||||
}
|
||||
|
||||
if(macro == 'attr'
|
||||
&& args.name != null
|
||||
&& ['title', 'path', 'location', 'dir'].indexOf(args.name) >= 0){
|
||||
return Wiki[args.name]
|
||||
}
|
||||
|
||||
return t
|
||||
})
|
||||
}
|
||||
|
||||
$('.text').html(setWikiWords(text, filters.indexOf('show_link_brackets') < 0 && editing))
|
||||
//*/
|
||||
|
||||
// XXX save...
|
||||
localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
|
||||
@ -195,6 +94,21 @@ $(() => {
|
||||
reload()
|
||||
|
||||
//update_editor()
|
||||
|
||||
$(window).on('hashchange', function(evt){
|
||||
evt.preventDefault()
|
||||
|
||||
var path = location.hash.slice(1)
|
||||
var hash = path.split('#')
|
||||
path = hash.shift()
|
||||
hash = hash.pop() || ''
|
||||
|
||||
go(path)
|
||||
|
||||
if(hash.length > 0){
|
||||
// XXX focus anchor...
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
39
wiki.js
39
wiki.js
@ -42,14 +42,25 @@ var setWikiWords = function(text, show_brackets, skip){
|
||||
.replace(
|
||||
Wiki.__wiki_link__,
|
||||
function(l){
|
||||
var path = l[0] == '[' ? l.slice(1, -1) : l
|
||||
var i = [].slice.call(arguments).slice(-2)[0]
|
||||
|
||||
/*
|
||||
// XXX HACK check if we are inside a tag...
|
||||
var rest = text.slice(i+1)
|
||||
if(rest.indexOf('>') < rest.indexOf('<')){
|
||||
return l
|
||||
}
|
||||
//*/
|
||||
|
||||
return skip.indexOf(l) < 0 ?
|
||||
('<a '
|
||||
+'class="wikiword" '
|
||||
+'href="#" '
|
||||
+'href="#'+ path +'" '
|
||||
+'bracketed="'+ (show_brackets && l[0] == '[' ? 'yes' : 'no') +'" '
|
||||
+'onclick="go($(this).text())" '
|
||||
+'onclick="go($(this).attr(\'href\').slice(1))" '
|
||||
+'>'
|
||||
+ (!!show_brackets && l[0] == '[' ? l.slice(1, -1) : l)
|
||||
+ (!!show_brackets ? path : l)
|
||||
+'</a>')
|
||||
: l
|
||||
})}
|
||||
@ -338,12 +349,12 @@ var macro = {
|
||||
// XXX not sure about these...
|
||||
// XXX add docs...
|
||||
var BaseData = {
|
||||
// Macro acces to standard page attributes...
|
||||
'System/title': function(){ return this.get('..').title },
|
||||
'System/path': function(){ return this.dir },
|
||||
'System/dir': function(){ return this.get('..').dir },
|
||||
'System/location': function(){ return this.dir },
|
||||
'System/resolved': function(){ return this.get('..').acquire() },
|
||||
// Macro acces to standard page attributes (paths)...
|
||||
'System/title': function(){ return '['+ this.get('..').title +']' },
|
||||
'System/path': function(){ return '['+ this.dir +']' },
|
||||
'System/dir': function(){ return '['+ this.get('..').dir +']' },
|
||||
'System/location': function(){ return '['+ this.dir +']' },
|
||||
'System/resolved': function(){ return '['+ this.get('..').acquire() +']' },
|
||||
|
||||
// page data...
|
||||
//
|
||||
@ -431,7 +442,7 @@ var BaseData = {
|
||||
// XXX add .json support...
|
||||
var data = {
|
||||
'Templates/EmptyPage': {
|
||||
text: 'Page [@include(./path)] is empty.' +'<br><br>'
|
||||
text: 'Page @include(./path) is empty.' +'<br><br>'
|
||||
+'Links to this page:' +'<br>'
|
||||
+'@include(./links)' +'<br><br>'
|
||||
+'---' +'<br>'
|
||||
@ -473,6 +484,7 @@ data.__proto__ = BaseData
|
||||
var Wiki = {
|
||||
__wiki_data: data,
|
||||
|
||||
__config_page__: 'System/config',
|
||||
__home_page__: 'WikiHome',
|
||||
__default_page__: 'EmptyPage',
|
||||
// Special sub-paths to look in on each level...
|
||||
@ -520,6 +532,13 @@ var Wiki = {
|
||||
get data(){
|
||||
return this.__wiki_data[this.acquire()] },
|
||||
|
||||
/*
|
||||
// XXX
|
||||
get config(){
|
||||
return this.__wiki_data[this.__config_page__] || {}
|
||||
},
|
||||
//*/
|
||||
|
||||
|
||||
// XXX
|
||||
clone: function(){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user