[TW5] Tag shortener macro

119 views
Skip to first unread message

The Bo

unread,
Nov 24, 2016, 2:08:07 AM11/24/16
to TiddlyWiki
Hey,

I want to display tags of tiddlers in a list. Now I need a solution to shorten the tag name.
I tried to build a macro similar to a macro I used before but I don't know how to get the "tag-variable".

Maybe someone can help me with this.

So far I have got this code:
/*\
title: $:/macros/tag_shortener.js
type: application/javascript
module-type: macro

Shorten a tag


\*/

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro
*/


exports
.name = "tag_shortener";

exports
.params = [
{name: "end_string"}
];

/*
Run the macro
*/

exports
.run = function(end_string) {
   
return this.getVariable("currentTiddler").substring(0, end_string);
};

})();


PMario

unread,
Nov 24, 2016, 4:08:38 AM11/24/16
to TiddlyWiki
Hi,

Can you describe, what you want to achieve instead of code that doesn't work.

I can see some facts:

 - show a list of tiddler tags
 - shorten the tag names

guessing:

 - short names should still link to tag tiddlers?
 - ???


The "splitbefore"  filter operator is no option? http://tiddlywiki.com/#Filter%20Operators:%5B%5BFilter%20Operators%5D%5D%20%5B%5Bsplitbefore%20Operator%5D%5D%20%5B%5Bsplitbefore%20Operator%20(Examples)%5D%5D

-m

The Bo

unread,
Nov 24, 2016, 4:46:50 AM11/24/16
to TiddlyWiki
Hi Mario,

the purpose is to find a way to highlight tiddlers in the "toc-navigation-tree" even if I just use the search function.
I see that a state tiddler (text: open) is created for every topic in the toc-navigation I open.
Now I want to change the search mechanism using the linkcatcher widget so that a state tiddler for every topic/subtopic is created.

My TOC is looking like this (reference no. / title):

01 Topic 1
  -> 010 Subtopic
      -> 0101 Subtopic
          Tiddler A (tagged 0101 Subtopic)
          Tiddler B (tagged 0101 Subtopic)
      -> 0102 Subtopic
      ....
  -> 011 Subtopic
  ....
02 Topic 2
...

If I can extract the reference no. of the tag of Tiddler A I will be able to extract the reference no. of every upper topic/tag (0101 -> 010 -> 01 -> TableofContents)
Like this I could created state tiddlers (text:open):
$:/state/toc/TableofContents-01 Topic 1--123124123
$:/state/toc/01 Topic 1-010 Subtopic--123124123
$:/state/toc/010 Subtopic-0101 Subtopic--123124123

Maybe it sounds a bit confusing, sorry about that.
I already tried to use the splitbefore filter operator but I think it won't fit for my purposes.

Regards,
The Bo

PMario

unread,
Nov 24, 2016, 5:20:11 AM11/24/16
to TiddlyWiki
Hi The Bo,

This is a completely different problem. ... and imo much more interesting than your first post :)
It's about predictable state names. ...

If you open the TOC in a tiddler like this: http://tiddlywiki.com/#TableOfContents
and you open a branch in the Contents tab, you'll see, that the created state tiddlers actually have a different number at the end. That's created with the qualify macro. So what you need imo is a new TOC macro, since the existing implementation uses qualify, which is completely unpredictable (for humans :).

If I'm remembering right, Eric Shulman has a custom TOC, that should exactly fit your needs. The TOC opens the branches according to the tiddler that's open in the story river. ... but I don't know the links :/

-mario


PMario

unread,
Nov 24, 2016, 5:23:57 AM11/24/16
to TiddlyWiki
Have a look at: https://youtu.be/j2Lz6CswsE8?t=3313 if that's what you need.

-m

The Bo

unread,
Nov 28, 2016, 3:35:26 AM11/28/16
to TiddlyWiki
Hey Mario,

this is what I'm looking for. Where can I find it?

Regards,
The Bo

PMario

unread,
Nov 28, 2016, 8:11:25 AM11/28/16
to TiddlyWiki
On Monday, November 28, 2016 at 9:35:26 AM UTC+1, The Bo wrote:
this is what I'm looking for. Where can I find it?

Hi,

In the last hangout, near the end, we discussed a possibility to bring some of Erics's stuff to the core.

What we want to have in the core in the short run:

 - recursion protection. ... to avoid javascript errors or endless trees.
 - auto select an open tiddler, in the TOC branches.

In the first run it should be a plugin, for easy testing.


see: http://tiddlytools.github.io/InsideTW/#PartsList ... TOC section. There are several macros involved. ...

I'll have a closer look and will create a pull request. ... Which doesn't mean, that I'm the only one, which can do this. So if someone is interested and faster than me, help is very welcome. Just drop me a line.

have fun!
mario




The Bo

unread,
Nov 29, 2016, 9:06:46 AM11/29/16
to TiddlyWiki
Thanks Mario, I will give it a try. ;-)

A core implementation would be awesome!
Reply all
Reply to author
Forward
0 new messages