From 70bda0a77445ebb28a1758e75e9dfd5d85902630 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 29 Jan 2018 01:28:40 +0100 Subject: Test in comment --- app.js | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 163 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index a6eeecf..ade15df 100644 --- a/app.js +++ b/app.js @@ -8,6 +8,137 @@ function locator(value, fromIndex) { var index = value.indexOf(START, fromIndex); return index; } +function prop2HTML( prop ) { + let html = ''; + + if( 'id' in prop && prop['id'] ) { + html += ' id=' + prop['id']; + } + if( 'class' in prop ) { + html += ' class="' + prop['class'].join(' ') + '"'; + } + if( 'key' in prop ) { + Object.entries(prop['key']).forEach( + ([key, value]) => { + html += ' ' + if(value) { + html += key+'="'+value+'"'; + }else{ + html +=key + } + } + ) + } + + return html +} + +function parseHTMLparam( value, indexNext ) { + let lets_eat = "{"; + indexNext++; + + const eat = ( ( chars ) => { + let eaten = "" + while(chars.indexOf(value.charAt(indexNext)) >= 0) { + lets_eat+=value.charAt(indexNext); + eaten +=value.charAt(indexNext); + indexNext++; + } + return eaten; + }); + const eat_until = ( ( chars ) => { + let eaten = "" + while(chars.indexOf(value.charAt(indexNext)) < 0) { + lets_eat+=value.charAt(indexNext); + eaten +=value.charAt(indexNext); + indexNext++; + } + return eaten; + }); + + + + let prop = {key:undefined /* {} */, 'class':undefined /*[]*/,id:undefined /*""*/} + let type; + + while(true) { + let labelFirst = ""; + let labelSecond = undefined; + + eat(' \t\n\r\v'); + + if( value.charAt(indexNext) == '}' ) { // Fin l'accolade + break; + } else if( value.charAt(indexNext) == '.' ) { // Classes + type = 'class'; + indexNext++; + lets_eat+='.' + } else if( value.charAt(indexNext) == '#' ) { // ID + type = 'id'; + indexNext++; + lets_eat+='#' + } else { // Key + type = 'key'; + } + + // Extract name + labelFirst = eat_until( '=\t\b\r\v  }') + + if( value.charAt(indexNext) == '=' ) { // Set labelSecond + indexNext++; + lets_eat+='='; + + if( value.charAt(indexNext) == '"' ) { + indexNext++; + lets_eat+='"'; + labelSecond = eat_until('"}\n') + + if( value.charAt(indexNext) != '"' ) { + // Erreur + }else{ + indexNext++; + lets_eat+='"'; + } + } else if( value.charAt(indexNext) == "'" ) { + indexNext++; + lets_eat+="'"; + labelSecond = eat_until("'}\n") + + if( value.charAt(indexNext) !="'" ) { + // Erreur + }else{ + indexNext++; + lets_eat+="'"; + } + } else { + labelSecond = eat_until(' \t\n\r\v=}'); + } + } + switch( type ) { + case 'id': // ID + prop['id']=labelFirst; + break; + case 'class': + if( ! prop['class'] ) + prop['class'] = [] + prop['class'].push(labelFirst); + break; + case 'key': + if( !prop['key'] ) prop['key'] = {}; + if( labelFirst != 'id' && labelFirst != 'class' ) + prop['key'][labelFirst] = labelSecond ? labelSecond : ''; + break; + } + if( labelSecond ) + console.log("{{" + labelFirst + "=" + labelSecond + "}}"); + else + console.log("{{" + labelFirst + "}}"); + } + lets_eat+="}"; + + return {type:type, prop:prop, eaten:lets_eat}; + +} function plugin() { function blockTokenizer(eat, value, silent) { @@ -15,11 +146,41 @@ function plugin() { if (!this.options.gfm || value.search(START) != 0) { return; } + let prop = {key:undefined /* {} */, 'class':undefined /*[]*/,id:undefined /*""*/}; + let eaten = ''; + console.log(value[value.search(END)+value.match(END)[0].length]) + if( value.charAt(value.search(END)+value.match(END)[0].length) == '{' ) { + let res = parseHTMLparam( value, value.search(END)+value.match(END)[0].length); + eaten = res.eaten; + console.log(res.eaten); + prop=res.prop; + } + console.log(prop2HTML(prop)); if( value.search(END) > 0 ) { - return eat(value.slice(0,value.search(END))+value.match(END)[0])({ + return eat(value.slice(0,value.search(END))+value.match(END)[0]+eaten)({ type:'html', - value:'' + value:'' + value.slice(value.match(START)[0].length+1, value.search(END)-1 ) + '' /* + + type: 'form', + data: { + hName:'form', + hChildren : [ { + type: 'element', + tagName:'div', + properties: {}, + children: [ { + type:'element', + tagName: 'textarea', + properties: prop, + children: [ { type: 'text', + value: value.slice(value.match(START)[0].length+1, value.search(END)-1 ) + } ] + }] + }, { type:'element', tagName:'div', properties:{} } ] + } + + type: 'form', children: [ { type: 'texterea', -- cgit v1.2.3