TypeError: this.formatter.formatters[t-1] is undefined

35 views
Skip to first unread message

Tobias Beer

unread,
Mar 30, 2012, 4:02:03 PM3/30/12
to TiddlyWikiDev
Hi everyone,

I am trying to get to grips with formatters, but I guess I am just
wandering in the dark.

The formatter I constructed works well ...unless I add ANY other
afterwards:
http://hashtags.tiddlyspace.com/#HashTagsPlugin

...see formatter below comment:
//formatter for #tag

...and also:
//formatter for ::category:tag::

Any formatter inserted after either fails, as you can see here...
http://hashtags.tiddlyspace.com/#ThumbsUp

For some reason <Wikifier.prototype.subWikifyTerm> fails with these
formatters.

There is something to either one of them which is provoking this
behaviour also previously reported here:
http://groups.google.com/group/tiddlywikidev/browse_thread/thread/cd2c718ecb8771f2

Formatters inserted by other plugins fail as well when inserted into
the formatters array after mine got inserted.

It get's even weirder if I add yet another formatter behind it...
http://dl.dropbox.com/u/2040050/group/2012.03.30FormatterMadness.html#ThumbsUp

By the way, chrome reports this error instead:
TypeError: Cannot call method 'handler' of undefined

Any help greatly appreciated.

Tobias.

----

Some background: The first formatter is supposed to identify a
#hashtag inline while the other is supposed to
identify ::this:pattern:: and do something with <this> and
<pattern> ...which will eventually also require to insert it at the
beginning of the formatters array for it to work, as :: is reserved
for definition lists at the beginning of a line... which it shouldn't
be, but that's another topic. The idea for the latter is explained
here:
http://hashtags.tiddlyspace.com/#%5B%5BInline%20Tags%5D%5D

Tobias Beer

unread,
Mar 30, 2012, 5:23:25 PM3/30/12
to tiddly...@googlegroups.com
I have narrowed it down a bit.

The error is also provoked, when I empty both handlers, so they do nothing.

This means that:

1) There is something malformed about either of <match> or <lookaheadRegExp>. In general, both seem to at least follow the convention that the first is a string and the second a regex.

2) The handlers don't do something crucial they're supposed to do when making use of a lookaheadRegExp.

Keep in mind that in combination with ANY other extra formatter, BOTH formatters <hashtag> and <itag> provoke the same error.


Tobias.

Jeremy Ruston

unread,
Mar 31, 2012, 4:55:35 AM3/31/12
to tiddly...@googlegroups.com
Hi Tobias

I'm sorry I've not been more active in helping you debug these issues;
I've been away from a real computer.

I think the issue here is that your 'match' patterns for both the
formatters include capturing parenthesis. This is not allowed, because
the wikification matching mechanism concatenates all the match
expressions into one giant regexp, and then relies on there being a
1:1 correspondence between each formatter and a single set of
capturing parenthesis. You can see what is going on in the constructor
to the Formatter() object:

https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/FormatterHelpers.js

The built-in "rawText" formatter is a good example of the way to
workaround this problem. Here, the match expression is just the
minimum pattern to trigger the formatter. Then the body resets the
match position to the beginning of the match before testing for the
lookahead regexp:

this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);

This means that the string that triggered the formatter is re-parsed
as part of the lookahead search, allowing capturing parentheses to be
used to extract the bits and pieces.

Best wishes

Jeremy

> --
> You received this message because you are subscribed to the Google Groups
> "TiddlyWikiDev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/tiddlywikidev/-/Sj2gzaNOXj8J.
>
> To post to this group, send email to tiddly...@googlegroups.com.
> To unsubscribe from this group, send email to
> tiddlywikide...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/tiddlywikidev?hl=en.

--
Jeremy Ruston
mailto:jeremy...@gmail.com
http://www.tiddlywiki.com

Tobias Beer

unread,
Mar 31, 2012, 7:23:15 AM3/31/12
to tiddly...@googlegroups.com
Hi Jeremy,

Thanks a lot for taking the time to explain this in detail. Your explanations make a lot of sense when thinking about it. After a minute of quick testing ...it seems to work just fine now. Great!

Have a nice weekend, Tobias.
Reply all
Reply to author
Forward
0 new messages