playing with the parser...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-10-28 23:28:50 +03:00
parent 52cdbcc63d
commit c60569e021
2 changed files with 50 additions and 35 deletions

View File

@ -259,7 +259,7 @@ Replaced with current page title.
**`$INDEX`** **`$INDEX`**
Replaced with current page index in pattern selection. Replaced with current page index in pattern matching.

View File

@ -474,6 +474,7 @@ module = {
// /SomePage/SomePage // /SomePage/SomePage
// or any path matching: // or any path matching:
// /\/(SomePage\/)+/ // /\/(SomePage\/)+/
// XXX slow when lots of pages need to be included...
parse: function(context, text, state, skip_post, pattern){ parse: function(context, text, state, skip_post, pattern){
var that = this var that = this
@ -551,16 +552,22 @@ module = {
// #text / comment node -> parse the @... macros... // #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... // get actual element content...
var text = $('<div>').append($(e).clone()).html() var text = e.nodeValue
// conditional comment... // conditional comment...
if(e.nodeType == e.COMMENT_NODE if(e.nodeType == e.COMMENT_NODE){
&& /^<!--\s*\[pWiki\[(.|\n)*\]\]\s*-->$/.test(text)){ text = /^<!--\s*\[pWiki\[(.|\n)*\]\]\s*-->$/.test(text) ?
text = text text
.replace(/^<!--\s*\[pWiki\[/, '') .replace(/^<!--\s*\[pWiki\[/, '')
.replace(/\]\]\s*-->$/, '') .replace(/\]\]\s*-->$/, '')
: ('<!--'+ text +'-->')
} }
/*
var t = _parseText(context, text, macro)
text != t
&& $(e).replaceWith(t)
//*/
$(e).replaceWith(_parseText(context, text, macro)) $(e).replaceWith(_parseText(context, text, macro))
// node -> html-style + attrs... // node -> html-style + attrs...
@ -627,9 +634,14 @@ module = {
// filter stage... // filter stage...
_filter(state.filters.concat(this.__filters__), this.filter) _filter(state.filters.concat(this.__filters__), this.filter)
// XXX DEBUG...
var t = Date.now()
console.log('>>>', context.path())
// merge includes... // merge includes...
parsed parsed
.html(parsed.html().replace(include_marker, function(){ .html(parsed.html()
.replace(include_marker, function(){
var page = state.include.shift() var page = state.include.shift()
var elem = $(page.shift()) var elem = $(page.shift())
page = page.pop() page = page.pop()
@ -660,6 +672,9 @@ module = {
}).join('\n') }).join('\n')
})) }))
// XXX DEBUG...
console.log('<<<', context.path(),'TIME:', Date.now() - t)
// post processing... // post processing...
if(!skip_post){ if(!skip_post){
// fill slots... // fill slots...