Whoa Stephan!

That bookmarklet is seriously useful. Thank you! I can use it for this but 
the script is also clear enough I could adapt it to other use cases too. 
Thanks!

If you read my earlier message you see I found another solution that uses 
CSS counters for the particular use case. 

BTW, your Replace Pragma (slightly dangerous :-) first opened my eyes to 
the huge utility of direct access to "raw" regular expressions in TW. I now 
mostly use BJ's "Flexity" variant of his "Flexible Types" plugin that lets 
you do much the same--and avoid some of the issues with your pragma as it 
runs before other processing. The example I gave that started this thread 
was created using it. I do think "raw" style regex access in TW has huge 
potential. I noticed you interested in using it for extraction globally 
across a whole TW. Right? Great stuff.

Best wishes
Josiah

Stephan Hradek wrote:
>
> If a bookmarklet is enough, here you go:
>
> javascript:var ta= document.activeElement.contentWindow.document.
> querySelector('textarea');
> var numbers= new Object();
> var number= /^(.*?)\s*#(\d+)$/;
> if(ta !== null && ta.tagName.toLowerCase() == 'textarea') {
>     var content= JSON.parse(ta.value);
>     for (var i=0; i<content.length; ++i) {
>         var title= content[i].title;
>         if(title === undefined) {
>             continue;
>         }
>         var hasnumber= number.exec(title);
>         if(hasnumber === null) {
>             if(numbers[title] === undefined) {
>                 numbers[title]= "0001";
>             } else {
>                 numbers[title]= ((("10"+numbers[title])*1+1)+"").replace(
> /^10?/, "")
>             }
>             content[i].title+= " #"+numbers[title];
>         } else {
>             numbers[hasnumber[1]]= hasnumber[2];
>             continue;
>         }
>     }
>     ta.value= JSON.stringify(content,0,2);
> }
> void(0);
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/d96cdc7f-72d0-488f-bbe7-308c7fe382c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to