Creating new tiddler types

56 views
Skip to first unread message

stefano franchi

unread,
Feb 15, 2019, 2:05:12 PM2/15/19
to TiddlyWikiDev
How does the addition of new tiddler types work?

From reading the railroad plugin code and the tw-dev pages on Parser and Widget, I gather that it is as simple as creating a new parser module and assigning the newly defined type to a specific widget.

Railroad does it in its  super-simple typed-parser.js module:
```
(function(){

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

var RailroadParser = function(type,text,options) {
    var element = {
            type: "railroad",
            tag: "$railroad",
            text: text
        };
    this.tree = [element];
console.log(text);
};

exports["text/vnd.tiddlywiki.railroad"] = RailroadParser;

})();
...

The intent is clear, and the code could not be simpler. It maps the new  tiddler type text/vnd.tiddlywiki.railroad to the railroad plugin. But it feels like a bit of magic. Where is that mapping actually established?  I have not been able to find how it  actually implemented  in the core, and I would like to get a better grasp of the overall mechanism. Where should I look?

Cheers,

S.
--
__________________________________________________
Stefano Franchi

stefano...@gmail.com
http://stefano.cleinias.org

Jeremy Ruston

unread,
Feb 16, 2019, 4:51:42 AM2/16/19
to tiddly...@googlegroups.com
Hi Stefano

I think you've got it exactly right. The details tying the mechanism together are in the wiki.parseText() method.

Best wishes

Jeremy
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/CAJODLwZodcay8hnXKBDK%2BJK%3DDs_X2NNfx9ZAXZeqdDDBiXvXBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

stefano franchi

unread,
Feb 16, 2019, 9:30:35 AM2/16/19
to TiddlyWikiDev
On Sat, Feb 16, 2019 at 3:51 AM Jeremy Ruston <jeremy...@gmail.com> wrote:
Hi Stefano

I think you've got it exactly right. The details tying the mechanism together are in the wiki.parseText() method.


Thanks Jeremy,
now I finally get it. Inturn, it is the wiki.initParsers() method that sets up the mapping. I had totally missed that.

Cheers,

S.
Reply all
Reply to author
Forward
0 new messages