mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-19 09:31: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/jquery.js"></script>
|
||||||
<script src="ext-lib/pouchdb.min.js"></script>
|
<script src="ext-lib/pouchdb.min.js"></script>
|
||||||
|
<script src="ext-lib/peer.min.js"></script>
|
||||||
<script src="wiki.js"></script>
|
<script src="wiki.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -17,112 +18,10 @@ var clear = () => {
|
|||||||
delete localStorage['wiki-location']
|
delete localStorage['wiki-location']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var reload = () => {
|
var reload = () => {
|
||||||
|
|
||||||
//*
|
|
||||||
//$('.wiki').html(Wiki.text)
|
|
||||||
//var editing = $('.text').prop('contenteditable') != 'false'
|
|
||||||
|
|
||||||
$('.wiki')
|
$('.wiki')
|
||||||
.html(Wiki.get('./_view').text)
|
.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...
|
// XXX save...
|
||||||
localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
|
localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
|
||||||
@ -195,6 +94,21 @@ $(() => {
|
|||||||
reload()
|
reload()
|
||||||
|
|
||||||
//update_editor()
|
//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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
39
wiki.js
39
wiki.js
@ -42,14 +42,25 @@ var setWikiWords = function(text, show_brackets, skip){
|
|||||||
.replace(
|
.replace(
|
||||||
Wiki.__wiki_link__,
|
Wiki.__wiki_link__,
|
||||||
function(l){
|
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 ?
|
return skip.indexOf(l) < 0 ?
|
||||||
('<a '
|
('<a '
|
||||||
+'class="wikiword" '
|
+'class="wikiword" '
|
||||||
+'href="#" '
|
+'href="#'+ path +'" '
|
||||||
+'bracketed="'+ (show_brackets && l[0] == '[' ? 'yes' : 'no') +'" '
|
+'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>')
|
+'</a>')
|
||||||
: l
|
: l
|
||||||
})}
|
})}
|
||||||
@ -338,12 +349,12 @@ var macro = {
|
|||||||
// XXX not sure about these...
|
// XXX not sure about these...
|
||||||
// XXX add docs...
|
// XXX add docs...
|
||||||
var BaseData = {
|
var BaseData = {
|
||||||
// Macro acces to standard page attributes...
|
// Macro acces to standard page attributes (paths)...
|
||||||
'System/title': function(){ return this.get('..').title },
|
'System/title': function(){ return '['+ this.get('..').title +']' },
|
||||||
'System/path': function(){ return this.dir },
|
'System/path': function(){ return '['+ this.dir +']' },
|
||||||
'System/dir': function(){ return this.get('..').dir },
|
'System/dir': function(){ return '['+ this.get('..').dir +']' },
|
||||||
'System/location': function(){ return this.dir },
|
'System/location': function(){ return '['+ this.dir +']' },
|
||||||
'System/resolved': function(){ return this.get('..').acquire() },
|
'System/resolved': function(){ return '['+ this.get('..').acquire() +']' },
|
||||||
|
|
||||||
// page data...
|
// page data...
|
||||||
//
|
//
|
||||||
@ -431,7 +442,7 @@ var BaseData = {
|
|||||||
// XXX add .json support...
|
// XXX add .json support...
|
||||||
var data = {
|
var data = {
|
||||||
'Templates/EmptyPage': {
|
'Templates/EmptyPage': {
|
||||||
text: 'Page [@include(./path)] is empty.' +'<br><br>'
|
text: 'Page @include(./path) is empty.' +'<br><br>'
|
||||||
+'Links to this page:' +'<br>'
|
+'Links to this page:' +'<br>'
|
||||||
+'@include(./links)' +'<br><br>'
|
+'@include(./links)' +'<br><br>'
|
||||||
+'---' +'<br>'
|
+'---' +'<br>'
|
||||||
@ -473,6 +484,7 @@ data.__proto__ = BaseData
|
|||||||
var Wiki = {
|
var Wiki = {
|
||||||
__wiki_data: data,
|
__wiki_data: data,
|
||||||
|
|
||||||
|
__config_page__: 'System/config',
|
||||||
__home_page__: 'WikiHome',
|
__home_page__: 'WikiHome',
|
||||||
__default_page__: 'EmptyPage',
|
__default_page__: 'EmptyPage',
|
||||||
// Special sub-paths to look in on each level...
|
// Special sub-paths to look in on each level...
|
||||||
@ -520,6 +532,13 @@ var Wiki = {
|
|||||||
get data(){
|
get data(){
|
||||||
return this.__wiki_data[this.acquire()] },
|
return this.__wiki_data[this.acquire()] },
|
||||||
|
|
||||||
|
/*
|
||||||
|
// XXX
|
||||||
|
get config(){
|
||||||
|
return this.__wiki_data[this.__config_page__] || {}
|
||||||
|
},
|
||||||
|
//*/
|
||||||
|
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
clone: function(){
|
clone: function(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user