I didn't understand a word of this, but I too would like to know if Yakov's 
code could be added to the core. 

Cheers!
-Leo

On Friday, February 14, 2014 12:51:59 AM UTC-7, Yakov wrote:
>
> Ok, I've found sort of a proper solution. Let me first add some analysis 
> here.
>
> Like I said, the problem is that ("[["+args.join("]] [[")+"]]").
> readBracketedList() is not always the same thing as args. The reason is 
> args[i] may contain symbols that are considered by 
> .parseParams("list",null,false,true) (which is used in .
> readBracketedList()) as delimeters of "arguments" when reading the 
> bracketed lists (resulting in a wrong arguments' boundaries determination). 
> The study of regexps used in parseParams showed that such special symbols 
> are '"[]{}, and that's all. But to avoid problems, one has to avoid 2+ of 
> ' or " in args[i], so it's good enough to "remove" them at all.
>
> How to remove those symbols? It can be done by some sort of 
> encoding-decoding. escape, encodeURIcomponent use the "% encoding", which 
> is ok. But on decoding, combinations of %\w\w will be switched to symbols 
> (even if they were not obtained from encoding '"[]{}) which wouldn break 
> the identity of the transformation. So, the % symbol must be encoded as 
> well -- in this case we get an identity of the encoding + decoding 
> transformation. Next, we have to decide which encoding function to use. 
> encodeURIcomponent has a drawback: it doesn't encode the ' symbol. The 
> warning by MozillaDev about the escape function (mentioned above) sais 
> that it only works well enough with the ASCII symbols and that it is 
> considered deprecated. '"[]{}% symbols are all ASCII symbols, so the 
> escape function can be used here, unless the deprecated status worries us 
> too much. In this case, the solution would be:
>
> var badSymbolRegExp = /['"\[\]\{\}%]/g,
>     badSymbolEscapedRegExp = /%\w\w/g,
>     escapeBad   = function($0) { return escape($0) };
>     unescapeBad = function($0) { return unescape($0) };
> // use _.replace(badSymbolRegExp,escapeBad) in config.macros.tiddler.handler, 
> _.replace(badSymbolEscapedRegExp,unescapeBad) in 
> config.macros.tiddler.transclude
>
>
> The code snippet to play around is attached [*]. This is a tested solution 
> (in all 5 PC browsers, TW 2.6.5), works well with non-ASCII symbols as well 
> and solved my problem. I guess it can be brought to the core now (in the 
> form of changing the config.macros.tiddler.handler and 
> config.macros.tiddler.transclude, of'course).
>
> An alternative solution would be to make the regexps and 
> escaping/unescaping functions a bit more complicated to make them 
> substitute each symbol literaly: something like
>
> var badSymbolRegExp = /(')|(")|(\[)|(\])|(\{)|(\})|(%)]/g,
>
>     escapeBad = function($0,$1,$2,$3,$4,$5,$6,$7) {
>         if($1)
>             return "%27"
>         if($2)
>         ....
>     };
>
>
> but I don't think this deserves such a complication/code size.
>
> Eric and others, what do you think?
>
> Best regards,
> Yakov.
>
> [*]
>
> var badSymbolRegExp = /['"\[\]\{\}%]/g,
>     badSymbolEscapedRegExp = /%\w\w/g,
>     escapeBad   = function($0) { return escape($0) };
>     unescapeBad = function($0) { return unescape($0) };
> // use ...replace(badSymbolRegExp,escapeBad), 
> ...replace(badSymbolEscapedRegExp,unescapeBad)
>
> config.macros.tiddler.handler = 
> function(place,macroName,params,wikifier,paramString,tiddler) {
>
>       var allowEval = true;
>       var stack = config.macros.tiddler.tiddlerStack;
>       if(stack.length > 0 && config.evaluateMacroParameters == "system") {
>               // included tiddler and "system" evaluation required, so check 
> tiddler tagged appropriately
>               var title = stack[stack.length-1];
>               var pos = title.indexOf(config.textPrimitives.sectionSeparator);
>               if(pos != -1)
>                       title = title.substr(0,pos); // get the base tiddler 
> title
>               var t = store.getTiddler(title);
>               if(!t || t.tags.indexOf("systemAllowEval") == -1)
>                       allowEval = false;
>       }
>       params = paramString.parseParams("name",null,allowEval,false,true);
>       var names = params[0]["name"];
>       var tiddlerName = names[0];
>       var className = names[1] || null;
>       var args = params[0]["with"];
>       var wrapper = createTiddlyElement(place,"span",null,className,null,{
>               refresh: "content", tiddler: tiddlerName
>       });
>       var escapedArgs = []
>       if(args!==undefined) {
>               for(var i = 0; i < args.length; i++)
>                       
> escapedArgs.push(args[i].replace(badSymbolRegExp,escapeBad));
>               wrapper.setAttribute("args","[["+escapedArgs.join("]] 
> [[")+"]]");
>               wrapper.setAttribute("readableArgs","[["+args.join("]] 
> [[")+"]]");
>       }
>       this.transclude(wrapper,tiddlerName,args);
> };
>
> config.macros.tiddler.transclude = function(wrapper,tiddlerName,args) {
>
>       var text = store.getTiddlerText(tiddlerName);
>       if(!text)
>               return;
>       var stack = config.macros.tiddler.tiddlerStack;
>       if(stack.indexOf(tiddlerName) !== -1)
>               return;
>       stack.push(tiddlerName);
>       try {
>               var i;
>               if(typeof args == "string") {
>                       args = args.readBracketedList();
>                       for(i = 0; i < args.length; i++)
>                               args[i] = 
> args[i].replace(badSymbolEscapedRegExp,unescapeBad);
>               }
>               var n = args ? Math.min(args.length,9) : 0;
>               for(i = 0; i < n; i++) {
>                       var placeholderRE = new RegExp("\\$" + (i + 1),"mg");
>                       text = text.replace(placeholderRE,args[i]);
>               }
>               config.macros.tiddler.renderText(wrapper,text,tiddlerName);
>       } finally {
>               stack.pop();
>       }
> };
>
>
>
> понедельник, 3 февраля 2014 г., 5:26:36 UTC+4 пользователь Yakov написал:
>>
>> Hi Eric,
>>
>> понедельник, 3 февраля 2014 г., 5:02:22 UTC+4 пользователь Eric Shulman 
>> написал:
>>>
>>> On Sunday, February 2, 2014 4:31:46 PM UTC-8, Yakov wrote:
>>>>
>>>>
>>>> <<fet *filter '$1'* sortableBy '"$2"' script 'var wrapTitle = 
>>>> function(text,tid){
>>>>   return tid.tags.contains("emphasis") ? 
>>>> "@@font-weight:bold;font-size:inherit;"+text+"@@" : text;
>>>> };
>>>> ...
>>>> The symptom is the following: as the whole thing is transcluded and 
>>>> wikified (<<tiddler [[SListTemplate##main]] 
>>>> *with:"[tag[current]]"*with:"orderCurrent" with:'tag:"current" 
>>>> tag:"steps"'>>), 
>>>> it works as expected; but on refreshing I get a list of two tiddlers: 
>>>> tag and current (the parts of the [tag[current]] filter).
>>>>
>>>
>>> As a workaround, you might try avoiding the use of square brackets in 
>>> the parameter by changing the <<fet>> like this:
>>>    <<fet *filter '[tag[$1]]'* sortableBy '"$2"' ...
>>> and then invoke it like this:
>>>    <<tiddler [[SListTemplate##main]] *with:"current"* ...
>>>
>>> the intention (and, well, actual usage) already includes more 
>> complicated filters, so this is not a workaround that would fit. Anyway, 
>> it's better to fix the issue instead of workaround, I guess.
>>  
>>
>>> enjoy,
>>> -e
>>> Eric Shulman
>>> TiddlyTools / ELS Design Studios
>>>
>>> EVERY DONATION IS IMPORTANT!
>>> HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...
>>>    http://TiddlyTools.github.com/fundraising.html#MakeADonation
>>>
>>> Professional TiddlyWiki Consulting Services...
>>> Analysis, Design, and Custom Solutions:
>>>    http://www.TiddlyTools.com/#Contact
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywikidev@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to