From 0773f7e39e67ce0f81008d9350cf7c8136c05885 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Wed, 7 Oct 2009 16:37:27 +0000 Subject: [PATCH] * quick hack at recursive template parsing probably should be replaced by some more feature complete / planed out javasciprt wikit text parsing approach ) --- js2/mwEmbed/mv_embed.js | 240 +++++++++++++++++--------------- js2/mwEmbed/tests/testLang.html | 6 +- js2/mwEmbed/tests/testLangEn.js | 2 +- 3 files changed, 131 insertions(+), 117 deletions(-) diff --git a/js2/mwEmbed/mv_embed.js b/js2/mwEmbed/mv_embed.js index 5cf4a4a3c6..9a1b12efbd 100644 --- a/js2/mwEmbed/mv_embed.js +++ b/js2/mwEmbed/mv_embed.js @@ -393,104 +393,137 @@ if( !mv_embed_path ) { var ts = '' ; var curt = 0 ; var schar = 0; - for ( var a = 0 ; a < this.wikiText.length ; a++ ) { - if ( this.wikiText[a] == '{' && this.wikiText[a+1] == '{' ) { - //set the start index if the outer most template: - if( tcnt == 0 ) - schar = a; - - tcnt++ ; - a++ ; - if ( tcnt > 1 ) ts += '{{' ; - } else if ( this.wikiText[a] == '}' && this.wikiText[a+1] == '}' ) { - if ( tcnt > 1 ) ts += '}}' ; - if ( tcnt > 0 ) tcnt-- ; - if ( tcnt == 0 ) { - curt++ ; - //@@todo handle type stuff - tObj = { - "s" : schar, - "e" : a + 2, - "iText" : ts - } - //Get template name: - tname = ts.split('\|').shift() ; - tname = tname.split('\{').shift() ; - tname = tname.replace( /^\s+|\s+$/g, "" ); //trim - //check for arguments: - if( tname.split(':').length == 1 ){ - tObj["name"] = tname - }else{ - tObj["name"] = tname.split(':').shift(); - tObj["arg"] = tname.split(':').pop(); - } + + + //build out nested template holders: + var depth = 0; + var tKey = 0; + var ns = ''; - //set template params - //get all the params (not including the name) - var cat = ts; - - var pSet = ts.split('\|'); - pSet.splice(0,1); - if( pSet.length ){ - tObj.param = new Array(); - for(var pInx in pSet){ - var tStr = pSet[ pInx ]; - for(var b=0 ; b < tStr.length ; b++){ - if(tStr[b] == '=' && b>0 && b' + numVal + '' + '' + mKey + '' + diff --git a/js2/mwEmbed/tests/testLangEn.js b/js2/mwEmbed/tests/testLangEn.js index 3a5255abff..711da44b44 100644 --- a/js2/mwEmbed/tests/testLangEn.js +++ b/js2/mwEmbed/tests/testLangEn.js @@ -7,7 +7,7 @@ loadGM({ 'test_plural_msg' : '{{PLURAL:$1|one|other}}', //sample real world msgs: 'undelete_short' : 'Undelete {{PLURAL:$1|one edit|$1 edits}}', - 'category-subcat-count' : "{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}" + 'category-subcat-count' : "fish {{PLURAL:$2|This {{PLURAL:$1|fistsub|$1 secondsub}} category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}" }); $mw.lang.loadRS({ -- 2.20.1