Forloop plugin by ibnishak.github.io

65 views
Skip to first unread message

Bala Chandra

unread,
Apr 29, 2018, 10:03:52 AM4/29/18
to TiddlyWikiDev
It replaces only the first instance of the forvar .. So i tried to modify the code of $:/plugins/tesseract/forloop/forloop.js  (https://ibnishak.github.io/Tesseract/pluginsandmacros/index.html#Simple%20for-loop%20macro)


        for (; i <= max; i += iter) {
            textBuffer.push(text.replace(forvar, i));
        }

to

        for (; i <= max; i += iter) {
            textBuffer.push(text.replace(/forvar/gi, i));
        }

However, even then the code doesnt do a global replace ... any ideas?

BJ

unread,
Apr 29, 2018, 4:19:26 PM4/29/18
to TiddlyWikiDev
you need to do it like this:
var re = new RegExp(forvar, 'g');
for (; i <= max; i += iter) {
       textBuffer.push(text.replace(re, i));
}
all the best BJ

Bala Chandra

unread,
May 2, 2018, 10:21:52 PM5/2/18
to TiddlyWikiDev
Thanks a lot .. that helped :)
Reply all
Reply to author
Forward
0 new messages