Making wikilinks from a list of tiddlers - solved! :-)

40 views
Skip to first unread message

Måns

unread,
Sep 10, 2009, 12:28:10 PM9/10/09
to TiddlyWiki
Hi TwWizards

I'm proud to tell that I've composed a script, which takes a
lineseperated list - and converts it to a lineseperated list with
double bracketed listitems.
Something I have tried to accomplish for the last few months...

It's a combination of two scripts Eric Shulman showed me in another
context - and I don't know if there's more code in it than it needs -
please tell if it's the case.

I use it in the toolbarcommands.
It takes the lineseperated list in the active tiddler and transposes
it to a list of bracketed wikilinks:

<script label="L2W" title="convert list to wikilinks">
var here=story.findContainingTiddler(place);
if (!here) return;
var title=here.getAttribute("tiddler");
var tid=store.getTiddler(title);
var t=store.getTiddlerText(tiddler.title) ;
var target = store.getTiddler(tiddler.title) ;
var txt='[['+tid.text.split('\n').join(']]\n[[')+']]';
store.saveTiddler
(tid.title,tid.title,txt,tid.modifier,tid.modified,tid.tags,tid.fields);
</script>

I plan to use it like this:
1) I paste a lineseperated list into a tiddler
2) I "run" the script(A"L2W") on the list to get doublebracketed
listitems
3) I run another script(B)* on the (now linking) listitems, which
tag's all listitems with a predefined tagname.

My next challenge will be to change script(B)* so it also can be
invoked from the toolbar - *and* it should also prompt for tagname!

The best solution would be to combine the two scripts in one script -
so they were run consecutively - Then we would have a script which
could tag a linesperated list of items with a tag - However script
(A"L2W") should be able to be reversed (again consecutively) to remove
the doubled brackets after the tagging has taken place (script(C)??)-
so the list appears as it was from the start.
This way the doublebracketing is only temporary - to let script(B)* do
it's job.

*script(B):
<script label="script(B)" title="tag bracketed list with tagName">
var tid=prompt("tagName");
if (!tid) return; /* cancelled by user */
var txt=store.getTiddlerText(tid);
if (!txt) { alert(tid+" not found"); return; }
var titles=txt.readBracketedList();
for (var i=0; i<titles.length; i++) store.setTiddlerTag(titles
[i],true,'HoldListeBilleder');
</script>

YS Måns Mårtensson

Måns

unread,
Sep 10, 2009, 12:33:40 PM9/10/09
to TiddlyWiki
Sorry - script(B) was wrong:

<script label="script(B)" title="Tag tiddlers from a list with
doublebracketed listitems">
var tid=prompt("title of the tiddler with the list");
if (!tid) return; /* cancelled by user */
var txt=store.getTiddlerText(tid);
if (!txt) { alert(tid+" not found"); return; }
var titles=txt.readBracketedList();
for (var i=0; i<titles.length; i++) store.setTiddlerTag(titles
[i],true,'TagName');
</script>
Reply all
Reply to author
Forward
0 new messages