Is it a feasible to create a Markdown convertor viewtoolbar button based on the markdown export plug in

https://cdaven.github.io/tiddlywiki/#Markdown%20Export%20Plugin

This is the markdown export plug in by cdaven. Is it possible to make use of this plug-in to create a view toolbar button which can do any of the given below functions -

  1. clone a wikitext tiddler to convert and save it as a additional markdown tiddler
  2. replace the original wikitext tiddler with its markdown copy
  3. copy to clipboard the tiddler content in markdown format.

I couldn’t find any clues after going through the markdown export plug-in tiddlers.

Hmm… I didn’t know about this plugin and it seems like a good jumping off point. I’d like to convert a back catalog of wikitext tiddlers to markdown but exporting one by one and reimporting seems like it would be a chore.

Seems like it might have potential. You can just use his export template to convert text

So this button will take the contents of TestTiddler, convert them to markdown, and put them in “MarkDownTest”.

It puts the meta data at the top (because it’s expecting to export), but I imagine that could be factored out.

<$button>Wikify Test
<$wikify name=md text="""{{TestTiddler||$:/plugins/cdaven/markdown-export/md-tiddler}}""">
<$action-setfield $tiddler="MarkDownTest" text=<<md>> />
</$wikify>
</$button>

there is a md to tid button can be used as example GitHub - tiddly-gittly/md-to-tid: Transform markdown to tiddlywiki5 wikitext syntax. Using unifiedjs.

Thank you @Mark_S for taking a look at this.
I created a test wiki based on your code. https://md-convertor-test.tiddlyhost.com/

But the conversion doesn’t seem to happen correctly. Is that a bug with the plug in ? Check this md-convertor tiddler and the converted tiddler.

Also is this saving template of any use. I got it from github

@Mark_S this md-to-tid viewtoolbar button works well - check this markdown tiddler and click on the viewtoolbar button to see the conversion happening.

@linonetwo is it possible to create a viewtoolbar button that can do the reverse, tid-to-md conversion. If that happens it would be super easy to switch between md and wikitext formats of a tiddler just on a button click.

It needs a wikiast-util-to-md similar to wikiast-util-to-wikitext from GitHub - tiddly-gittly/wikiast: Wiki AST transformation for WYSIWYG editor and advanced dynamic widgets in Tiddlywiki. , which requires much work to do, and is too easy so it is boring for me. But if someone want to make it, can use ChatGPT to mimic the wikiast-util-to-wikitext package, and PR to the repo, and I will use it in md-to-tid.

You’ve set it up to convert a markdown tiddler to a markdown tiddler. No telling what happens then.

When I tried it on your liver & coffee tiddler, I got

Which doesn’t look to bad. I assume the stuff (mostly meta) floating on the right has something to do with the extra markdown plugins you have installed.

My bad. I was testing your code in a wiki without markdown plug in. That was the missing point. Now only I realized that. When I set up the demo wiki, I accidentally set it like an md-to-md conversion. Now I have corrected the demo. I also added type="text/markdown" to the set field widget. Now its working.

<$action-setfield $tiddler="tid-to-md" type="text/markdown" text=<<md>>  />

Can this code be modified to create a view toolbar button which converts the wikitext in the tiddler text field to markdown format and change the tiddler type field to text/markdown

I tried something like this

<$button class=<<tv-config-toolbar-class>>> {{$:/core/images/excise}}
<$action-setfield $tiddler=<<currentTiddler>> type="text/markdown"  text=<<mdtiddler>>/>
</$button>

But the wiki is getting unresponsive and shows javascript error on creating this button tiddler due to too much recursion.

After closing the button tiddler from the storyriver, I tried to convert one wikitext tiddler to md and it was working. Reverse conversion from md to wikitext was possible with md-to-tid convertor by @linonetwo .

How to improve my code to avoid the error due to too much recursion and also how to avoid the front matter during this conversion?

\whitespace trim
<$list filter="[all[tiddlers]has[note]]">
<$button class=<<tv-config-toolbar-class>>> {{$:/core/images/excise}}
<$action-setfield $tiddler=<<currentTiddler>>  type="text/markdown"  text=<<mdtiddler>>/>
</$button>
</$list>

Adding a list filter like shown in the code above resolved the recursion issue. Can you suggest a better filter
Now how to avoid the frontmatter during the conversion?

So here’s a kit to make a tw-to-markdown edit toolbar button. Note that I overwrote one of cdaven’s plugin tiddlers to remove the meta info, so it can’t be used in the node export mechanism (because the meta info is now missing).

markdown-toolbar-button-kit.json (7.4 KB)

1 Like

Thank you @Mark_S for putting so much of effort on this.

Any particular reason why you preferred it as an editor toolbar button.

If I remember correctly, you do use markdown in your wikis. Any downside for using markdown and wikitext tiddlers intermixed in wikis. I was thinking whether I should use markdown for study note tiddlers.

Oh dang. You meant the other toolbar. Well, they’re about the same.

I keep wondering that too. Markdown is not, out of the box, as extensive or sensible as wikitext. But almost certainly markdown will still be here in 20 years. So … flexibility, or longevity?

I guess you can forge the way and tell us all how it goes mixing up the two types.

Edit:

Here’s the view toolbar. The button will disappear after the conversion to reduce possibility of running a tiddler through twice. The other JSON needs to be previously loaded.

markdown-view-toolbar-button.json (1017 Bytes)

So, at the moment you’ll have to decide if you want to export as markdown, or convert-in-place. It would take more work to make both work at once.

Edit 2: Where do I find these doctors that recommend 3 cups of coffee? And how do they feel about oatmilk?

I want to try markdown in my note tiddlers mainly because of the perceived longevity aspect . Lets see how it goes. Because real-time conversion from md to tid and tid to md is now possible as a result of the two toolbar buttons as mentioned in this thread, I don’t see any problem in trying markdown for sometime.

There are two add ons available for markdown in TW - tw-markdown-more by @cdruan and editor-autolist-markdown by @jasonmhoule I guess. These two plug ins looks interesting and make me try out markdown.

Thank @Mark_S once again for sharing the viewtoolbar button.

Another doubt:

Have you tried referencing local images using relative path in markdown tiddlers. In my wikitext tiddlers its working. But when I tried to convert a wikitext tiddler containing local images referenced via relative path, the syntax of the converted images was like this ![](filename as relative path)

For example in wikitext the image syntax was [img[media/Tweet-ASK_MSK-septo-optic dysplasia2023_2_24 18_09_51.png]]

On md conversion, the image syntax becomes ![](media/Tweet-ASK_MSK-septo-optic dysplasia2023_2_24 18_09_51.png)

The image is not getting rendered with this md syntax , while the same image in wikitext syntax get rendered in markdown tiddlers also. What is going wrong here ?

Coffee tiddler is taken from a tweet made by a doctor whom I follow in twitter - https://twitter.com/theliverdr - he is a hepatologist from my state (Kerala)- a controversial guy since he tweet much against traditional medicine here in India. If you search his timeline you may find something about oatmeal.

The markdown plugin, and possibly all markdown parsers, don’t know how to deal with spaces. You can make it work by replacing the space with %20

I would consider eliminating spaces in my file names, especially if the goal was longevity.

I will try my luck there. … my wikis are loaded with lots of external local images which I reference using relative path. I will have to find some way to get images working if I have to use markdown.