Something Like a Table of Contents

I’m adding some functionality to my Captain’s Log, “daily notes” Tinderbox, inspired by Tom Erickson’s Proteus notebook (1996).

Captain’s Log is structured as a kind of deck log, with containers for Year, Month, Day and Entry. I use Tabs to constrain a view to a given Month or Day.

After some time, this becomes a rather long list of entries in a month, and visually scanning them from the Month view only gives the entry titles, which may not be enough to prompt recall of what the entry was about. (There are special categories of entries that are tagged or otherwise identified by prototype (special icons), which can be gathered by agents.)

Erickson writes:

Section and Subsection TOCs

The section and subsection TOCs are simply lists of their contents. The section TOC contains a list ofsubsections, and the subsection TOC contains a list of pages (where each page is represented by the first line of its contents). Clicking on any item in the TOC will take you to the appropriate page. Figure 3 shows an example of a subsection TOC (the “May '94” subsection of the “Daily Notes” section ). (Over time a convention has evolved of summarizing a content page’s important entries on its first line, enabling the TOC page to function as a sort of abstract or summary of its subsection.)

What I have conceived is using the $Text of a Month container in a similar fashion. What I’ve been able to accomplish so far is to create, for now, a Stamp:

$Text=collect(descendants,$Subtitle).replace(";","\n");

I’m using a Rule in a prototype p_Note to create $Subtitle:

$Subtitle=$Name+": "+$Text;

So far, everything seems to work. I suppose there may be a more elegant, or more generalized solution using $MyString in lieu of $Subtitle, but it was easier for me to figure out how to use $Subtitle. (I originally tried to see if collect() could return more than one attribute, $Name and the first line of $Text, but I don’t think that’s possible.)

I have two questions. The first perhaps relates to the “type” of data collect() returns, as the $Text that the stamp is applied to opens and closes with a square bracket “[” and “]”. I’d like to make those go away, mostly for aesthetic reasons. (Parenthetically, semi-colons in the source note $Text do some weird things, which is why they’re missing in Yeats.)

I suspect there may be some fancy “replace” thing I need to do, but it eludes me just now.

The far more challenging question is how do I make each of these lines in the Month container’s $Text, link to their original note (entry)?

For the moment, I see this stamp being applied at the close of a month, so it would be a “one and done,” action.

Since Day containers generally contain no $Text, they make a nice divider:

So, how do I make the square brackets go away?
How do I make each of those lines in $Text link to their source notes?
(I’m getting better, but this is a bit more advanced than I can begin to conceive a solution.)

I started a little model file to accomplish this part, and I’ve attached it here.
TOC Test.tbx (217.4 KB)

1 Like

If you know that a string begins and ends with square brackets, the inside can be extracted with .substr(1,-1) — the substring that starts 1 character from the beginning, and ends one character before the end.

But there isn’t currently a way to make text links in an action.

1 Like

I tried.
Maybe I am not doing it right, but I can also make text links with ziplink.

$Text=;
$MyList=collect(descendants,$ID);
$MyList.each(aID){
	var:string vTemp;
	if($Text(aID).size>0){
		$Text(aID).captureLine(vTemp);
	};
	$Text+= "[[" + $Name(aID) + "]]" + " : " + vTemp +"\n";
};

TOC Test2.tbx (282.9 KB)

2 Likes

Sorry, I have a problem with the text link. With this method, text links don’t work if there are duplicate note names, such as Day1.

That works! I didn’t know if I could chain .substr to the same collect().replace action, so I did a $MyString for the collect() and then the .substr from $MyString:

$MyString=collect(descendants,$Subtitle).replace(";","\n");
$Text=$MyString.substr(1,-1);

Are text links preserved in $Text if I did a more incremental TOC development, where I might do something like

$Text=$Text+$TOCString;

During daily review, I’d use a stamp to create a string ($TOCString) of the previous day’s entries, and append them to the existing $Text, which presumably would now contain text links manually created in the preceding days.

Those would be preserved, and I would only have to manually link the new days’ entries currently under review?

I don’t know why I’m asking! I’ll just go and try it in the model. BRB.

Update: I’m tripping over my shoelaces here. I’ll be back later if I can’t figure this out, but it’s going to take some time.

Dave, I’m curious, why populate text with all this data when you could use a template and you’d have so much more flexibility with the output.

1 Like

Or to avoid the implicit regex (though I doubt this strains your Mac):
$Text=collect(descendants,$Subtitle).format("\n");
You are seeing the [] because recent changes (improvements1) mean list (List or Set) data uses that to indicate broad type:

// old
"ant;bee;cow"
//new (for lists)
[ant;bee;cow]

With .replace() you are altering the content of the list (here a List-type). Using .format() does the type coercion List->String. So, same textual output but no square brackets. See List.format() for more.

As to #2, I think you want a different approach. Operators like `linkTo() create basic links but you want text links (i.e. links from anchor text in $Text) and u don’t think action code can do that. IOW, your problem isn’t making the anchor text, but rather making a link using that text—via action code.

[edit: whilst I was typing, @eastgate confirmed this latter constraint, notwithstanding @sazanamix’s work-around]

Time for some lateral thinking: export, or rather preview. If you view the container with a template with the code ^childLinks^, then you’ll see a set of functional links to the children. But edge-case point:

  • you export a blog so your TBX ‘preview’ pages will get generated in your export folder in the outline location of the previewed note. IOW, you can’t have export to h/d and internal-only preview.
  • but you could put a note elsewhere (i.e. not in a folder you expect to upload) and then ^include^ the desired container using a template with ^childLinks^. You will get some h/d files as a result of preview but you can easily delete or ignore that container and contents when uploading to your blog.
1 Like

I haven’t had chance to play with this, but in the actual case, most $Names will be unique, either because the day container is an actual date (I suppose they align periodically, but I’m anticipating keeping only two years in an active log.) The exception being a $Midwatch entry which is made every day by a function.

But I have to go do something now, so it’ll be later today before I can try this.

Thanks, though!

I will upload a revised version.

$Text=;
$MyList=collect(descendants,$ID);
$MyList.each(aID){
	var:string vTemp;
	if($Text(aID).size>0){
		$Text(aID).captureLine(vTemp);
	};
	$Text+= "[["+ $Path(aID)+"|"+$Name(aID) + "]]" + " : " + vTemp +"\n";
};

I don’t know because I haven’t tried it, but maybe the link is lost because [[and]] are not left as strings when the assignment is made.

TOC Test3.tbx (303.6 KB)

Heh, I should be getting ready to go work out. Personal trainer, so I can’t skip it.

I’m not looking to output anything. Everything I want to do, I can achieve within the features of the Tinderbox file itself.

Preview involves templates, which are another thing I have to manage; and they create external files, yet another thing I have to manage. I’d rather stay within the Tinderbox file, and just deal with action code.

I saw Erickson’s TOC and I thought that would be pretty straightforward to implement in TBX, and useful. It appears as though we may be able to create text links using [[ zip links ]], but I haven’t played with it yet. But making a half dozen or so text links manually every day or two during review doesn’t seem too onerous.

Nice solution, but the problem is likely the same as when using the ‘zip’ method in-app to make links. there you’d need to traverse the pop-up outline shown to pick the correct ‘Day 1’.

I’d have thought that as the code uses the target note $ID [sic] the name—only used as a *anchor text—ambiguity ought not to matter. But, we can’t see the innards of the zip-method linking.

The latter’s a shame else we’d have method to make text links. That said, finding a work in the middle of existing $Text and using this would be much harder as you’d have to split/re-join the existing $Text and doing so would/might likely thrown off the positioning of any pre-existing text links. IOW, though possible I’d not commit to extensive use of this except if making lists where i control all the text from outset.

For now, using preview seems a safer, more tractable method even if a different solution and with a few edge cases of its own.

2 Likes