How to render Markdown tiddlers with markdown-it from CLI?

Hi there, this time what I need to do is simple, I think, but not easy.

I have some tiddlers in my TiddlyWiki with MIME text/markdown, and they visualize fine in the TiddlyWiki web app with the markdown-it ($:/plugins/tiddlywiki/markdown, included in the official plugin repository) plugin installed. I can even export them to static HTML no problem, with the “export tiddler” button.

However, if I try to export those tiddlers via tiddlywiki CLI, they get rendered as if they where WikiText (for example, I see lines starting with #, indicating headings in Markdown, get rendered as ordinated list items in the static HTML)… this is a problem.

For reference, my render command is:

--rendertiddlers "[prefix[sitoctt:/]]" "$:/sitoctt/sitoctt.html" . text/plain

$:/sitoctt/sitoctt.html is just my render template, that I derived by adding extra code to $:/core/templates/static.tiddler.html, but if I were to use this latter built-in one as my render template, I would have the exact same issue.

I suspect the culprit to be this line in the render template:

<$view tiddler="$:/core/ui/ViewTemplate" format="htmlwikified"/>

It specifies for the content to be rendered in htmlwikified format, and this might be forcing TiddlyWiki to call the WikiText parser, instead of the Markdown one when needed.

If I edit the line to not specify anything, transclusion of the content into the render template doesn’t work. If I use the {{!!text}} syntax, or <$transclude/>, I just get a plaintext representation.

The ViewWidget documentation doesn’t help, and neither does the documentation included with the Markdown plugin.

I also tried editing the line to random combination of format=, like format="markdown", format="markdown-it", format="text/markdown", but nothing works.

Does anyone have any suggestion? Thank you…

Hi @_oct I’m sorry you’ve run into problems.

I tried exporting a couple of Markdown tiddlers from the demo edition that is included in the TiddlyWiki repo:

tiddlywiki editions/markdowndemo/ --rendertiddlers "[prefix[Quick]]" "$:/core/templates/static.tiddler.html" . "text/plain"

Two files were rendered into the output folder: “QuickDemo.html” and “QuickDemo%20Source.html” with the expected rendering of the Markdown content.

I don’t see much that can be wrong with the command you’ve shown, especially if you take your custom template out of the equation.

One thing to note is that format="htmlwikified" is definitely a red herring. Tiddlers are always wikified with the parser implied by their “type” field.

The symptoms you’re seeing would be consistent with the Markdown plugin not being loaded into the serverside wiki that you’re using. That would be the case if you had loaded the Markdown plugin in the browser using the plugin library. The correct way to load a plugin into a server side wiki is to include it in the tiddlywiki.info file for the wiki – see the documentation here.

I tried what you just did… and at first, it just didn’t work, it gave me the exact same problem as with my wiki (which, by the way, is loaded from as an HTML file and not as a folder, but has the markdown plugin installed).

But then, and I wish I had at least tried this before opening this thread, I simply tried to update the TiddlyWiki program installed on my system (sudo npm install -g tiddlywiki) and now, with no change whatsoever to my wiki, Markdown rendering works as expected. Also, your example now works.

I didn’t even pause for a second to think about what TiddlyWiki version I had installed because my HTML file is up-to-date, and so I always see “5.2.7”… Thank you anyways!

Hi @_oct I’m glad you’ve got it working

Can you show the node.js command you’re using to load the wiki? If you’re using --load path/to/file to load the HTML file, the markdown plugin will still need to be installed in the tiddlywiki.info file in order for it to work on the server.

This is my full command to build static HTML pages (don’t mind single words prefixed with $ and no other symbols, unlike $:/, they are variables in my sh script):

tiddlywiki \
	+plugins/tiddlywiki/markdown \
	--load ./sitocttTW.html \
	--output "$Output.tmp" \
	--rendertiddlers "[prefix[$Namespace:/]Template[$Template]]" "$:/sitoctt/$TemplateFile.html" . text/plain

There is no tiddlywiki.info in my folder, I only have the single HTML file as input; but I simply use the +PLUGIN syntax to load the Markdown plugin from the HTML wiki!

1 Like

Thanks @_oct that’s an excellent approach. It might be worth trying adding an explicit wiki folder, even though it would be empty:

tiddlywiki \
	+plugins/tiddlywiki/markdown \
	./my/wiki/folder \
	--load ./sitocttTW.html \
	--output "$Output.tmp" \
	--rendertiddlers "[prefix[$Namespace:/]Template[$Template]]" "$:/sitoctt/$TemplateFile.html" . text/plain