Is a widget the right way to convert a text spec into SVG?

I can see that the Railroad plugin uses a widget, but it’s a bit awkward to use, as the spec must either fit into an attribute or be in a separate tiddler.

It would feel so right to put the spec as the content of the DOM element. For this to work there would need a way to tag this element as “don’t parse the tree”, so that the wikiparser would skip it, and the widget would get an unparsed DOM and would be able to do whatever is needed with it.

For my case, which is also a multiline text spec that I want to convert to SVG, I am tempted to use a macro entirely written in javascript (which also feels awkward), just to have access to the unparsed content.

What do you think?

Hi @Jerome at the moment there is no way to have the content of a particular widget parsed differently. Instead, in such situations, the recommended approach is a custom parse rule that matches a suitable syntax.

Part of the difficulty is that widgets are dynamic: for example, the <$genesis> widget dynamically creates a widget which is not necessarily known at parse time, making it impossible to know how the content should be parsed. We could make it work in some situations, but it would be hard to make the behaviour universally consistent.

It might make sense to add a custom rule to the railroad plugin, particularly since we don’t have any other examples of the technique in the core.

For example:

...railroad
start [:optional] {repeated +","} end
...

The railroad plugin already has a content type handler defined, so Typed Blocks in WikiText already work:

$$$text/vnd.tiddlywiki.railroad
start [:optional] {repeated +","} end
$$$
1 Like

As far as I can tell, the Mermaid plugin (Mermaid TW5 Plugin — http://github.com/efurlanm/mermaid-tw5) also uses a content type handler and a widget.
@Jerome maybe Mermaid plugin code could be used as a starting point?

Fred

Sweet, so many options to chose from!

I’ll use typed block for now, thanks @btheado and @tw-FRed. And then I’ll have a look at adding a custom rule, thanks @jeremyruston.

Typed blocks! I think that’s how I should have done a lot of my widgets. There is far too much functionality to keep track of… :dizzy_face: