Patch for SectionLinksPlugin to prevent output at location of sectionTOC macro

12 views
Skip to first unread message

rouilj

unread,
Jul 3, 2009, 11:49:22 PM7/3/09
to TiddlyWiki
Hello all:

I am using version 1.2.0 of http://www.TiddlyTools.com/#SectionLinksPlugin.

As I mentioned in:

http://www.mail-archive.com/tiddl...@googlegroups.com/msg05141.html

I have an issue where I want to be able to suppress the toc that is
inserted by the <<sectionTOC>>
macro. At the bottom of my ViewTemplate I placed:
{{{
<span macro="sectionTOC '' silent"></span>
}}}
(note that is sectionTOC, two single quotes, silent and a double
quote).

I only want the TOC to show up if there is a {{sectionTOC{}}} (or
other specified class)
in the tiddler. To make this work I have modified the sectionTOC
definition to check for
a second parameter. So when invoked as: <<sectionTOC '' silent>> for
example, it suppresses
the default output at the location of the sectionTOC macro.

The following patch:
{{{
--- orig 2009-07-03 23:36:25.734375000 -0400
+++ new 2009-07-03 23:36:44.703125000 -0400
@@ -156,6 +156,7 @@
handler: function
(place,macroName,params,wikifier,paramString,tiddler) {
var out=[];
var targetClass=params[0]||this.targetClass;
+ var silent=params[1]||0; // if param1 exists display output only if
class marker exists.
var t=story.findContainingTiddler(place); if (!t) return;
var elems=t.getElementsByTagName("*");
var level=5; // topmost heading level
@@ -174,7 +175,12 @@
if (level>1) for (var i=0; i<out.length; i++) out[i]=out[i].substr
(level-1);
// show numbered list
if (target && target.style.display=='none')
target.style.display='block';
- wikify(out.join("\n"),target||place);
+ if ( ! silent ) {
+ wikify(out.join("\n"),target||place);
+ } else {
+ wikify(out.join("\n"),target);
+ }
+
}
}
//}}}
}}}

applied to the SectionLinksPlugin tiddler implements this
functionality.

A change to the documentation similar to:

{{{
Simply place the following macro at the //end of the tiddler
content// (i.e., following all section headings):
{ { {
<<sectionTOC>> or <<sectionTOC className [silent]>>
} } }

>Note: The macro must occur at the end of the tiddler in order to locate the rendered section headings that precede it. By default it places the table of contents at the location ofthe sectionTOC macro. However if the optional second parameter silent is supplied, no text will be produced at the location of the sectionTOC macro.
However, you can still position the ....
}}}

is also needed. Hopefully this will be useful to somebody and will
make it into a future version
of Eric Shulman's SectionLinksPlugin.

-- rouilj

Eric Shulman

unread,
Jul 4, 2009, 1:02:08 AM7/4/09
to TiddlyWiki
> I only want the TOC to show up if there is a {{sectionTOC{}}} (or
> other specified class) in the tiddler.
...
> added a second parameter. So when invoked as: <<sectionTOC '' silent>>

The currently supported way to do this is to add
<span class='sectionTOC'></span>
to the ViewTemplate, and then embed the
<<sectionTOC>>
macro at the end of each tiddler in which you want a TOC to be
generated and displayed.

In contrast, you are attempting the reverse approach by adding
<span macro='sectionTOC'></span>
to the end of the ViewTemplate, and then embedding
{{sectionTOC{}}}
within the desired tiddlers.

Of course, both methods are equally valid and can produce similarly
useful results. In fact, I think that the handling you described --
i.e., only rendering output if a matching 'target element' (e.g.,
{{sectionTOC{}}}) is present -- should be the *default* behavior...
after all, rendering a Table of Contents at the *end* of the tiddler
doesn't really make much sense!

I've just updated the plugin (v1.2.1):
http://www.TiddlyTools.com/#SectionLinksPlugin

After installing the update, you won't need to use either a classname
placeholder or a special "silent" param... just put the default
macro='sectionTOC' (with no params) at the end of the ViewTemplate and
then put the {{sectionTOC{}}} target element into each tiddler as
desired.

enjoy,
-e

rouilj

unread,
Jul 4, 2009, 1:12:20 AM7/4/09
to TiddlyWiki
Hi Eric:

On Jul 4, 1:02 am, Eric Shulman <elsdes...@gmail.com> wrote:
> > I only want the TOC to show up if there is a {{sectionTOC{}}} (or
> > other specified class) in the tiddler.
> ...
> > added a second parameter. So when invoked as: <<sectionTOC '' silent>>
>
> The currently supported way to do this is to add
>    <span class='sectionTOC'></span>
> to the ViewTemplate, and then embed the
>    <<sectionTOC>>
> macro at the end of each tiddler in which you want a TOC to be
> generated and displayed.
>
> In contrast, you are attempting the reverse approach by adding
>    <span macro='sectionTOC'></span>
> to the end of the ViewTemplate, and then embedding
>    {{sectionTOC{}}}
> within the desired tiddlers.
>
> Of course, both methods are equally valid and can produce similarly
> useful results.

The second way has the advantage that I can place front matter before
the TOC in the tiddler. If the {{sectionTOC{}}}
is embedded in the ViewTemplate, the toc has a fixed location.

>  In fact, I think that the handling you described --
> i.e., only rendering output if a matching 'target element' (e.g.,
> {{sectionTOC{}}}) is present --  should be the *default* behavior...
> after all, rendering a Table of Contents at the *end* of the tiddler
> doesn't really make much sense!

Yeah, that was kind of my idea.

> I've just updated the plugin (v1.2.1):
>    http://www.TiddlyTools.com/#SectionLinksPlugin
>
> After installing the update, you won't need to use either a classname
> placeholder or a special "silent"  param... just put the default
> macro='sectionTOC' (with no params) at the end of the ViewTemplate and
> then put the {{sectionTOC{}}} target element into each tiddler as
> desired.

Cool. Thanks for the fast update. I'll try it out and respond here if
I have any issues.

-- rouilj
Reply all
Reply to author
Forward
0 new messages