simple fix for the PublishMacro to maintain the tiddlylink labels

2 views
Skip to first unread message

ian

unread,
Jul 1, 2008, 5:36:05 PM7/1/08
to TiddlyWiki
Currently, the PublishMacro does not maintain Tiddlylink labels when
publishing to html.

For example:
[[my_cool_label|my_tiddlylink]]

will publish:
<a class="externalLink" href="my_tiddlylink.html">my_tiddlylink</a>

It does work for external hrefs though e.g. [[my_cool_label|http://
www.google.com]]

I made a simple modification to the PublishMacro:

var tiddlerName = result[i].match(/ tiddlylink="(.*?)"/i)[1];
var url = tiddlerName.htmlDecode().filenameEncode() + ".html";
//ian mod fix link labeling problem
var tiddlerLabel = result[i].match(/">(.*?)<\/a>/i)[1];
if (!className.match(/tiddlyLinkNonExisting/i))
wikiHTML = wikiHTML.myReplace(result[i], "<a class=\"" + className
+ "\" href=\"" + url + "\">" + tiddlerLabel + "</a>");

Just search for the first line of this code block to see the bits that
were changed.

Now, the same Tiddlylink example shown above should print as:
<a class="externalLink" href="my_tiddlylink.html">my_cool_label</a>

I tested this with the few html pages I am publishing, and all worked
- so hopefully the regex pattern works for others.

Thanks to Jack for a useful plugin.

ian

Ken Girard

unread,
Jul 1, 2008, 6:27:48 PM7/1/08
to TiddlyWiki
Shouldn't that come up as
<a class="externalLink"
href="my_tiddlylink.html#TiddlerTitle">my_cool_label</a> so as to
point at the correct tiddler?

Making the last line:

wikiHTML = wikiHTML.myReplace(result[i], "<a class=\"" + className
+ "\" href=\"" + url + "#" + tiddler.title + " \">" + tiddlerLabel +
"</a>");

Or does the plugin already take care of that part?

Ken Girard

ian

unread,
Jul 1, 2008, 8:23:18 PM7/1/08
to TiddlyWiki
I don't think so - I'm just publishing plain ol' html pages, they are
not embedded in a TW document.

So your example: my_tiddlylink.html#TiddlerTitle

would point to a header/anchor named TiddlerTitle in the page
my_tiddlylink.html

The title (found via regex in the tiddlerName variable) of a published
tiddler has .html appended to it to create the page filename(set in
the url variable) - so, anchors should still work, although none of my
pages are long enough to make use of anchors

Let me know if I misunderstood your question though.

When I clean everything up I can publish the relevant bits of the TW
file I created - assuming it is of interest to anyone.

ian

Marc J. Cawood

unread,
Jul 2, 2008, 11:38:33 AM7/2/08
to TiddlyWiki
Thanks Ian,
I've just updated the plugin in version 2.4.1 with your improvements.
http://jackparke.googlepages.com/jtw.html#PublishMacro
I also noticed internal links were not working at all in TW 2.4
because the order of attributes in wiki links has changed. I'm now
using a more powerful Regex to find the links.
Cheers
Marc (a.k.a. Jack)

Ken Girard

unread,
Jul 3, 2008, 12:51:59 PM7/3/08
to TiddlyWiki
OK, we are thinking of different uses.
I was trying to get the user back to my main TW page, and you are
keeping them in the created pages.

Ken Girard
> > > ian- Hide quoted text -
>
> - Show quoted text -

ian

unread,
Jul 3, 2008, 1:13:25 PM7/3/08
to TiddlyWiki
Marc: Thanks for updating the plugin so quickly, I'll update with your
latest version

Ken: Oh, I see now - this sounds useful too.
Reply all
Reply to author
Forward
0 new messages