mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-18 17:11:38 +00:00
cleaning up the parser...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a0ad716986
commit
cf32b82ef2
@ -25,7 +25,7 @@ var reload = () => {
|
|||||||
$('.title').text(Wiki.title)
|
$('.title').text(Wiki.title)
|
||||||
|
|
||||||
// process text...
|
// process text...
|
||||||
var text = Wiki.text
|
var text = Wiki.raw
|
||||||
var editing = $('.text').prop('contenteditable') != 'true'
|
var editing = $('.text').prop('contenteditable') != 'true'
|
||||||
var filters = []
|
var filters = []
|
||||||
var slots = {}
|
var slots = {}
|
||||||
@ -52,7 +52,7 @@ var reload = () => {
|
|||||||
if(macro == 'include' && args.length == 1){
|
if(macro == 'include' && args.length == 1){
|
||||||
w = Object.create(Wiki)
|
w = Object.create(Wiki)
|
||||||
w.location = args[0]
|
w.location = args[0]
|
||||||
return w.text
|
return w.raw
|
||||||
}
|
}
|
||||||
|
|
||||||
if(macro == 'attr'
|
if(macro == 'attr'
|
||||||
@ -86,7 +86,7 @@ var reload = () => {
|
|||||||
if(macro == 'include' && args.src != null){
|
if(macro == 'include' && args.src != null){
|
||||||
w = Object.create(Wiki)
|
w = Object.create(Wiki)
|
||||||
w.location = args.src
|
w.location = args.src
|
||||||
return w.text
|
return w.raw
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX need content...
|
// XXX need content...
|
||||||
|
|||||||
87
wiki.js
87
wiki.js
@ -28,26 +28,30 @@ var normalizePath = function(path){
|
|||||||
var clearWikiWords = function(elem){
|
var clearWikiWords = function(elem){
|
||||||
// clear existing...
|
// clear existing...
|
||||||
elem.find('.wikiword').each(function(){
|
elem.find('.wikiword').each(function(){
|
||||||
$(this).attr('braced') == 'yes' ?
|
$(this).attr('bracketed') == 'yes' ?
|
||||||
$(this).replaceWith(['['].concat(this.childNodes, [']']))
|
$(this).replaceWith(['['].concat(this.childNodes, [']']))
|
||||||
: $(this).replaceWith(this.childNodes)
|
: $(this).replaceWith(this.childNodes)
|
||||||
})
|
})
|
||||||
return elem }
|
return elem }
|
||||||
|
|
||||||
var setWikiWords = function(text, show_brackets){
|
var setWikiWords = function(text, show_brackets, skip){
|
||||||
|
skip = skip || []
|
||||||
|
skip = skip instanceof Array ? skip : [skip]
|
||||||
return text
|
return text
|
||||||
// set new...
|
// set new...
|
||||||
.replace(
|
.replace(
|
||||||
Wiki.__wiki_link__,
|
Wiki.__wiki_link__,
|
||||||
function(l){
|
function(l){
|
||||||
return '<a '
|
return skip.indexOf(l) < 0 ?
|
||||||
+'class="wikiword" '
|
('<a '
|
||||||
+'href="#" '
|
+'class="wikiword" '
|
||||||
+'braced="'+ (show_brackets && l[0] == '[' ? 'yes' : 'no') +'" '
|
+'href="#" '
|
||||||
+'onclick="go($(this).text())" '
|
+'bracketed="'+ (show_brackets && l[0] == '[' ? 'yes' : 'no') +'" '
|
||||||
+'>'
|
+'onclick="go($(this).text())" '
|
||||||
+ (!!show_brackets && l[0] == '[' ? l.slice(1, -1) : l)
|
+'>'
|
||||||
+'</a>'
|
+ (!!show_brackets && l[0] == '[' ? l.slice(1, -1) : l)
|
||||||
|
+'</a>')
|
||||||
|
: l
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
|
||||||
@ -106,18 +110,40 @@ var macro = {
|
|||||||
// include page/slot...
|
// include page/slot...
|
||||||
//
|
//
|
||||||
// NOTE: this will render the page in the caller's context.
|
// NOTE: this will render the page in the caller's context.
|
||||||
include_args: ['src', 'slot'],
|
// NOTE: included pages are rendered completely independently
|
||||||
|
// from the including page.
|
||||||
|
//
|
||||||
|
// XXX do we need to control the rendering of nested pages???
|
||||||
|
// ...currently I do not think so...
|
||||||
|
// ...if required this can be done via global and local
|
||||||
|
// filters... (now filters are only local)
|
||||||
|
// XXX do we need to render just one slot??? (slot arg)
|
||||||
|
include_args: ['src'],
|
||||||
include: function(context, args, _, state){
|
include: function(context, args, _, state){
|
||||||
var path = args.src
|
var path = args.src
|
||||||
|
|
||||||
var text = context.get(path).text
|
// XXX not sure if we need to render the source page relative
|
||||||
|
// to this or as-is...
|
||||||
//return this.parse(context, text)
|
state.include
|
||||||
state.include.push(this.parse(context, text))
|
//.push(this.parse(context, context.get(path).raw))
|
||||||
|
.push(context.get(path).text)
|
||||||
|
|
||||||
return this.__include_marker__
|
return this.__include_marker__
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
// NOTE: this is similar to include, the difference is that this
|
||||||
|
// includes the page source to the current context while
|
||||||
|
// include works in an isolated context
|
||||||
|
// XXX currently this will not parse the target...
|
||||||
|
source_args: ['src'],
|
||||||
|
source: function(context, args, _, state){
|
||||||
|
var path = args.src
|
||||||
|
|
||||||
|
return context.get(path).raw
|
||||||
|
},
|
||||||
|
//*/
|
||||||
|
|
||||||
// fill/define slot (stage 1)...
|
// fill/define slot (stage 1)...
|
||||||
slot_args: ['name'],
|
slot_args: ['name'],
|
||||||
slot: function(context, args, text, state){
|
slot: function(context, args, text, state){
|
||||||
@ -135,8 +161,7 @@ var macro = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
// stage 2...
|
// stage 2...
|
||||||
// XXX rename...
|
post_macro: {
|
||||||
macro2: {
|
|
||||||
slot_args: ['name'],
|
slot_args: ['name'],
|
||||||
slot: function(context, args, text, state){
|
slot: function(context, args, text, state){
|
||||||
var name = args.name
|
var name = args.name
|
||||||
@ -152,13 +177,9 @@ var macro = {
|
|||||||
|
|
||||||
// Filters...
|
// Filters...
|
||||||
//
|
//
|
||||||
// NOTE: a filter should be applicable multiple times without any
|
// Signature:
|
||||||
// side effects...
|
// filter(text) -> html
|
||||||
// XXX is this good???
|
|
||||||
//
|
//
|
||||||
// XXX this is preliminary...
|
|
||||||
// XXX add wikiword...
|
|
||||||
// filter(text) -> html
|
|
||||||
filter: {
|
filter: {
|
||||||
default: 'html',
|
default: 'html',
|
||||||
|
|
||||||
@ -167,7 +188,8 @@ var macro = {
|
|||||||
json: 'text',
|
json: 'text',
|
||||||
text: function(context, text){ return $('<div>').text(text).html() },
|
text: function(context, text){ return $('<div>').text(text).html() },
|
||||||
|
|
||||||
wikiword: function(context, text){ return setWikiWords(text) },
|
wikiword: function(context, text){
|
||||||
|
return setWikiWords(text, null, this.__include_marker__) },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -204,9 +226,9 @@ var macro = {
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
parse: function(context, text){
|
parse: function(context, text, state){
|
||||||
var that = this
|
var that = this
|
||||||
var state = {
|
state = state || {
|
||||||
filters: [],
|
filters: [],
|
||||||
slots: {},
|
slots: {},
|
||||||
include: [],
|
include: [],
|
||||||
@ -231,7 +253,12 @@ var macro = {
|
|||||||
text = _parse(context, text, this.macro)
|
text = _parse(context, text, this.macro)
|
||||||
|
|
||||||
// macro stage 2...
|
// macro stage 2...
|
||||||
text = _parse(context, text, this.macro2)
|
text = _parse(context, text, this.post_macro)
|
||||||
|
|
||||||
|
// XXX for some reason the next line parses WikiHome twice, once
|
||||||
|
// with -wikiword and oce without...
|
||||||
|
// $('body').html(Wiki.get('WikiHome/_view').text)
|
||||||
|
console.log('filters:', state.filters, text.slice(0, 60))
|
||||||
|
|
||||||
// filter stage....
|
// filter stage....
|
||||||
state.filters
|
state.filters
|
||||||
@ -265,6 +292,7 @@ var macro = {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// merge includes...
|
// merge includes...
|
||||||
|
// XXX need to check for errors (includes too short/long)...
|
||||||
text = text.replace(RegExp(this.__include_marker__, 'g'), function(){
|
text = text.replace(RegExp(this.__include_marker__, 'g'), function(){
|
||||||
return state.include.shift()
|
return state.include.shift()
|
||||||
})
|
})
|
||||||
@ -629,10 +657,7 @@ var Wiki = {
|
|||||||
this.__wiki_data[l].links = this.links
|
this.__wiki_data[l].links = this.links
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX take .raw, parse macros and apply filters...
|
get text(){ return macro.parse(this, this.raw) },
|
||||||
get text(){ return this.raw },
|
|
||||||
|
|
||||||
get _text(){ return macro.parse(this, this.raw) },
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE: this is set by setting .text
|
// NOTE: this is set by setting .text
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user