diff --git a/index.html b/index.html index 37505e7..b3aa1da 100755 --- a/index.html +++ b/index.html @@ -20,6 +20,16 @@ var clear = () => { 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) @@ -112,6 +122,7 @@ var reload = () => { } $('.text').html(setWikiWords(text, filters.indexOf('show_link_brackets') < 0 && editing)) + //*/ // XXX save... localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data) @@ -120,7 +131,38 @@ var reload = () => { $('title').text(Wiki.location) } +var update_editor = function(){ + // XXX make this update on enter... + $('.title') + .on('blur', () => { + Wiki.title = $('.title').text() + reload() + }) + + // live update text... + // XXX is this the right way to go for large documents??? + $('.text') + .focus(() => { + console.log('EDITING...') + $('.text').prop('contenteditable', $('.text').prop('contenteditable') != 'true') + reload() + }) + .on('keyup', () => { + if($('.text').prop('contenteditable') == 'true'){ + Wiki.raw = clearWikiWords($('.text').clone()).html() + } + }) + // XXX do this live, but on a timeout after user input... + // XXX need to place the cursor in the same position... + .blur(() => { + $('.text').prop('contenteditable', false) + reload() + }) +} + var go = (path) => { + console.log('GO:', path) + path = path.trim() path = path[0] == '[' ? path.slice(1, -1) : path @@ -152,40 +194,18 @@ $(() => { reload() - // XXX make this update on enter... - $('.title') - .on('blur', () => { - Wiki.title = $('.title').text() - reload() - }) - - // live update text... - // XXX is this the right way to go for large documents??? - $('.text') - .focus(() => { - $('.text').prop('contenteditable', $('.text').prop('contenteditable') != 'true') - reload() - }) - .on('keyup', () => { - if($('.text').prop('contenteditable') == 'true'){ - Wiki.raw = clearWikiWords($('.text').clone()).html() - } - }) - // XXX do this live, but on a timeout after user input... - // XXX need to place the cursor in the same position... - .blur(() => { - $('.text').prop('contenteditable', false) - reload() - }) + //update_editor() }) -
+
+ + diff --git a/wiki.js b/wiki.js index bed7381..1a6264c 100755 --- a/wiki.js +++ b/wiki.js @@ -118,16 +118,23 @@ var macro = { // ...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) + // XXX might be a good idea to wrap the result in a tag to enable + // in-place editing... include_args: ['src'], include: function(context, args, _, state){ var path = args.src - // XXX not sure if we need to render the source page relative - // to this or as-is... + // get and prepare the included page... state.include - //.push(this.parse(context, context.get(path).raw)) - .push(context.get(path).text) + .push(context.get(path)) + /* + // XXX do we need to quote the path here??? ...might get wikiword-ed ;) + .push('' + +context.get(path).text + +'') + //*/ + // return the marker... return this.__include_marker__ }, @@ -189,7 +196,7 @@ var macro = { text: function(context, text){ return $('
').text(text).html() }, wikiword: function(context, text){ - return setWikiWords(text, null, this.__include_marker__) }, + return setWikiWords(text, true, this.__include_marker__) }, }, @@ -255,11 +262,6 @@ var macro = { // macro stage 2... 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.... state.filters .concat(this.__filters__) @@ -294,7 +296,16 @@ var macro = { // merge includes... // XXX need to check for errors (includes too short/long)... text = text.replace(RegExp(this.__include_marker__, 'g'), function(){ - return state.include.shift() + var page = state.include.shift() + // NOTE: we are quoting html here, this is done to prevent + // included html from messing up the outer structure with + // things like unclosed tags and stuff... + // XXX can this be anything other than html? + return $('') + .addClass('include') + .attr('src', page.path) + .html(page.text)[0] + .outerHTML }) return text @@ -404,11 +415,14 @@ var data = { 'Templates/_view': { text: '\n' - +'
/@include(../path) ([../_edit])
\n' + +'
@include(../path) ([../_edit])
\n' +'
\n' - +'

@include(../title)

\n' + +'

@include(../title)

\n' +'
\n' - +'
@include(../text)
\n' + +'
@include(..)
\n' + +'\n' +'\n', }, 'Templates/_edit': { @@ -417,7 +431,7 @@ var data = { +'
\n' +'

@include(../title)

\n' +'
\n' - +'
@include(../text)
\n' + +'
@include(../raw)
\n' +'\n' @@ -657,7 +671,12 @@ var Wiki = { this.__wiki_data[l].links = this.links }, - get text(){ return macro.parse(this, this.raw) }, + // XXX not sure if this should return special function result as-is... + // ...might be better to just special-case the 'raw' in path... + get text(){ + // special case: if we are getting ./raw then do not parse text... + return this.title == 'raw' ? this.raw + : macro.parse(this, this.raw) }, // NOTE: this is set by setting .text