automatic editing of tiddlers

51 views
Skip to first unread message

skye riquelme

unread,
Feb 29, 2012, 11:32:17 PM2/29/12
to TiddlyWiki
Hi Again

I am wanting to change the text in a large numer of tiddlers....they
follow a simple pattern and the editing of the text is quite straight
forward. But I cant get the script to make the changes to the original
tidller........

I have ----
<script>
var ref="???";
var out="";
var tids="";
var tids=store.getMatchingTiddlers(ref);
for (var t=0; t<tids.length; t++) {
var title=tids[t].title;
var tags=tids[t].tags;
var who=tids[t].modifier;
var text=tids[t].text;
var firstreplace=text.replace("<<tiddler Format##pdf with:'","|
Link|");
........so the text is currently changed as I want.... ut then I
tried...
store.saveTiddler(title, title, newtext, who, null, tags,null);
autoSaveChanges();

...but it does not seem to override the old text.....

..I have tried store.setTiddlerText....but cant get the syntax
right....

HELP
Thanks
Skye

HansBKK

unread,
Mar 1, 2012, 11:24:27 PM3/1/12
to tiddl...@googlegroups.com
Open up the HTML file with your favorite code editor, or treat it as plaintext with your favorite regexp text-processing tools.

Eric Shulman

unread,
Mar 2, 2012, 12:47:11 AM3/2/12
to TiddlyWiki
On Feb 29, 8:32 pm, skye riquelme <riquelme.s...@gmail.com> wrote:
> I am wanting to change the text in a large numer of tiddlers....they
> follow a simple pattern and the editing of the text is quite straight
> forward. But I cant get the script to make the changes to the original
> tidller........

If you are just doing this on a one-time basis, you should be able to
use
http://www.TiddlyTools.com/#TiddlerTweakerPlugin
which will let you select multiple tiddlers and then replace text,
based on a *pattern*.

However, if the purpose of your script is to generalize the process
for repeated use, then we need to figure out what is wrong with the
code. Let's take it a few lines at a time:

> <script>
> var ref="???";
* I assume that ??? is replaced by some tag value to match using
MatchTagsPlugin

> var out="";
> var tids="";
* These aren't actually needed, and can be omitted.

> var tids=store.getMatchingTiddlers(ref);
* This uses the MatchTagsPlugin-defined function,
store.getMatchingTiddlers(). You could also write this using a TWCore
function, like this: store.filterTiddlers("[tag["+ref+"]]")

> for (var t=0; t<tids.length; t++) {
> var title=tids[t].title;
> var tags=tids[t].tags;
> var who=tids[t].modifier;
> var text=tids[t].text;
* OK... you're unpacking each tiddler's parts into separate
variables for easy reference (see note below)

> var firstreplace=text.replace("<<tiddler Format##pdf with:'","|
> Link|");
* OK... and then make the substitution in the text
* and store the result in 'firstreplace'

> ........so the text is currently changed as I want.... but then I
> tried...
> store.saveTiddler(title, title, newtext, who, null, tags,null);
> ...but it does not seem to override the old text.....
* you never actually defined the variable 'newtext', so it defaults
to NULL, so the text in the tiddler is not changed. You need to use
the 'firstreplace' variable that already contains the desired new text
content.
* also, since you only want to change the text content, and leave
everything else the same, you don't need to 'unpack' all those
separate variables that you defined above (except for 'text', which
you use in "text.replace(...)". Instead, you can simply refer to the
tiddler properties directly in the call to saveTiddler(), like this:
store.saveTiddler( tids[t].title, tids[t].title,
firstreplace, tids[t].modifier, tids[t].modified,
tids[t].tags, tids[t].fields);
* Note that this usage ensures that *only* the text content of the
tiddler is changed, and all other existing tiddler values are passed
along as-is, including the author, date, tags and custom fields.

That should cover it. Let me know how it goes...

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

----
WAS THIS ANSWER HELPFUL? IF SO, PLEASE MAKE A DONATION
http://www.TiddlyTools.com/#Donations
note: donations are directly used to pay for food, rent,
gas, net connection, etc., so please give generously and often!

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact

skye riquelme

unread,
Mar 2, 2012, 11:01:20 AM3/2/12
to TiddlyWiki
Hi Again

Thanks Eric..... so now I have

<script>
var ref="???";
var tids=store.getMatchingTiddlers(ref);
for (var t=0; t<tids.length; t++)
{
var text=tids[t].text;
var firstreplace=text.replace("<<tiddler Format##pdf with:'","|
Link|");
var endref=firstreplace.indexOf(">>");
var fullref=firstreplace.slice(0,endref);
var newtext=fullref+"|\n|Autor||\n|Editora||\n|Fonte|www|\n|Tipo|pdf|\n
\n!!Comentarios\n";
return newtext;
store.saveTiddler( tids[t].title, tids[t].title, newtext,
tids[t].modifier, tids[t].modified,tids[t].tags, tids[t].fields);
autoSaveChanges();
story.displayTiddler(tids[t].title,null);
}
</script>

..yes...in this case I am searching for tag "???" and only want to
change the text......in my code I output newtext.....and can see that
the string manipulation of the original text is correct....but it is
still not overwriting the new text.....the tiddler still shows the
original text...seems the store.saveTiddler part is not
functioning...thats the part that I cant get right.

You mentioned I could use "text.replace(..)" ... I am not familiar
with that function...how does it work...syntax...

Thanks
Skye

Eric Shulman

unread,
Mar 2, 2012, 11:46:03 AM3/2/12
to TiddlyWiki

> var newtext=fullref+"|\n|Autor||\n|Editora||\n|Fonte|www|\n|Tipo|pdf|\n
> \n!!Comentarios\n";
> return newtext;

^^^^^^^^^^^ WHY?!? (this *ends* the script *without saving the
tiddler*... *none* of the code that follows it will *ever* be invoked)

>       store.saveTiddler( tids[t].title, tids[t].title, newtext,
> tids[t].modifier, tids[t].modified,tids[t].tags, tids[t].fields);
> </script>


> You mentioned I could use "text.replace(..)" ... I am not familiar
> with that function...how does it work...syntax...

You are *already* using the .replace(...) function, here:

var firstreplace=text.replace("<<tiddler Format##pdf with:'","|
Link|");

Any decent online Javascript reference will have the full syntax and
usage.

-e

skye riquelme

unread,
Mar 2, 2012, 5:54:05 PM3/2/12
to TiddlyWiki
Opa....

I was not aware that the return ends the scrip......now you point it
out it seems so obvious !!!

text.replace...I thought you were refering to a TW function and not
the basic javascript....

guess I should go back to bed and try again tomorrow....when my brain
is fully engaged...

thanks for your patience!!!

Skye
Reply all
Reply to author
Forward
0 new messages