I have been experimenting with importing images into tiddlywiki and found some code - https://groups.google.com/g/tiddlywiki/c/1yTi65sc8D8/m/0ru-PhMJBAAJ - that does the job perfectly. However, it creates a kind of garbled button that displays all of the code contained within the button element as the button label, am I missing something obvious here?
In HTML that would be a void element so you can close it without the trailing forward-slash (like how <br> is valid for example, or putting an <li> on a newline without closing it).
@pmario are void widgets something which has been considered for the serialiser, just based on meeting user expectations?
The TiddlyWiki parser uses the stricter and more consistent XHTML standard that requires all widgets to be properly nested and closed. When widget content is not needed, the TiddlyWiki parser does permit the use of the closing /> sequence, but there are NO void widgets in TiddlyWiki.
Note that some TiddlyWiki widgets ignore their content (e.g., some – but not all – $action widgets) or have optional content; e.g, the $transclude widget, which uses the optional content as a fallback if the transcluded tiddler, field, or index does not exist.
Note also that as of v5.2.0 (3rd October 2021), the $action-createtiddlerCAN have optional content, as described in the ActionCreateTiddlerWidget documentation:
The content of the $action-createtiddler widget is executed after the new tiddler has been created. The title of the newly created tiddler is stored in the variable createTiddler-title.
The following tags are treated as ‘void’. This means that <tag> is treated as if it were <tag/>, and that no terminating </tag> is needed (if one is provided it will be ignored and treated as plain text).
I think Eric answered the current behaviour in detail. Since I am named directly I want to answer the question about: Did we consider void widgets.
As far as I can remember, the initial widget design always needed a <$start-tag> and an </$end-tag>. Widgets either ignore their content (if not needed) or use it as a template.
The self closing syntax was something that came later.
If we would have defined void widgets instead, it would be pretty hard to change that behaviour later, in a backwards compatible way.
As Eric pointed out, we did change the behaviour of the action-createtiddler, without causing any compatibility problems.
We could say, that was “by design” … But may be there was “luck too”