From 2260f75e8c0e66730735fd9f82b5b3bb9c09acaf Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 10 Jul 2016 02:41:31 +0300 Subject: [PATCH] experimenting with macros... Signed-off-by: Alex A. Naanou --- index.html | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- wiki.js | 9 +++++--- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 070efab..40f79e0 100755 --- a/index.html +++ b/index.html @@ -21,7 +21,57 @@ var reload = () => { $('.title').text(Wiki.title) - $('.text').html(activateWikiWords(Wiki.text)) + // process text... + var text = Wiki.text + + // expand macros... + if($('.text').prop('contenteditable') != 'true'){ + text = text + // Syntax: + // @( ) + .replace(/@([a-zA-Z-_]+)\(([^)]*)\)/g, function(_, macro, args){ + args = $('
') + .html(args) + .text() + .trim() + .split(/\s+/g) + + //console.log('>>>>>', macro, args) + + if(macro == 'include' && args.length == 1){ + w = Object.create(Wiki) + w.location = args[0] + return w.text + } + + return _ + }) + // html-like macro syntax... + .replace(/\<[a-zA-Z-_:]+.*?\/?\>/g, function(t){ + var elem = $($('
').html(t).text()) + var macro = elem.prop('tagName').toLowerCase() + + var args = {} + var a = elem.prop('attributes') + + for(var i=0; i>>>>', macro, args) + + if(macro == 'include' && args.src != null){ + w = Object.create(Wiki) + w.location = args.src + return w.text + } + + + return t + }) + } + + $('.text').html(activateWikiWords(text)) // XXX save... localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data) @@ -85,11 +135,21 @@ $(() => { // 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', () => { - Wiki.text = clearWikiWords($('.text').clone()).html() }) + if($('.text').prop('contenteditable') == 'true'){ + Wiki.text = 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(() => { reload() }) + .blur(() => { + $('.text').prop('contenteditable', false) + reload() + }) }) @@ -98,7 +158,7 @@ $(() => {

-
+
diff --git a/wiki.js b/wiki.js index 24c83e7..0518242 100755 --- a/wiki.js +++ b/wiki.js @@ -21,7 +21,8 @@ var BaseData = { } return null }) - .filter((e) => e != null) + .filter(e => e != null) + .map(e => '['+ e +']') .join('
') }, 'Templates/tree': function(){ @@ -34,7 +35,8 @@ var BaseData = { } return null }) - .filter((e) => e != null) + .filter(e => e != null) + .map(e => '['+ e +']') .join('
') }, 'Templates/links': function(){ @@ -53,7 +55,8 @@ var BaseData = { }) return res - .map(e => '['+ e[0] +'] from page: '+ e[1] +'') + //.map(e => '['+ e[0] +'] from page: ['+ e[1] +']') + .map(e => '['+ e[1] +'] -> ['+ e[0] +']') .join('
') },