henriklovhaug / md-tui

Markdown renderer in the terminal
GNU Affero General Public License v3.0
197 stars 12 forks source link

Support Mermaid #76

Open Fildor opened 6 months ago

Fildor commented 6 months ago

Feature suggestion:

Support embedded mermaid rendering.

henriklovhaug commented 6 months ago

Hi. Thanks for submitting an issue.

That kind of drawing seems like a major challenge to achieve in a terminal. It won't be started on any time soon I'm afraid, but I'll keep it in mind.

To spitball ideas, would some kind of ASCII drawing be sufficient here?

Fildor commented 6 months ago

would some kind of ASCII drawing be sufficient here?

That's actually a genius idea. That would solve the problem of Terminal Emulators that don't have image support.

It won't be started on any time soon

That's totally fine. I was just using this very cool tool and thought "this would be nice" - just because I happen to use mermaid quite a bunch. So, I felt like "lighting a spark" and hoped you liked the idea.

Best wishes, Fil

henriklovhaug commented 4 months ago

Circling back to this after a while. Most implementations I find is either the mermaid.js or a thin wrapper around it. I don't particularly like the idea of requiring or shipping a javascript runtime with MD-TUI. Looking at the specification, it's a lot they are offering. So the question is, what is the critical pieces of the mermaid.js to make it usable enough? If I am to go down the path of just implementing it myself.

divanvisagie commented 3 months ago

I have an idea, although it makes some assumptions. If the image support uses imgcat as an external command, couldn't we use an external command to generate an image from the mermaid code and then render that image?

henriklovhaug commented 3 months ago

The image support does not use imgcat as an external command. I'm not against using an external command to create the Mermaid picture and just render it, as long as the feature stays opt-in.

divanvisagie commented 3 months ago

I was thinking of trying something out that sort of works like a plugin that will pre-process the markdown before running it so that its essentially just pointing to the image.

I will create a fork and give it a bash so that I can represent my idea in code.

divanvisagie commented 3 months ago

Alright I have my quick and dirty POC, its a hack for sure.

Basically we just hook into the creation of the Code Block component and do the work of rendering the image and then return an image component instead of a code block if the conditions are met (in this case its mermaid code).

One thing I am thinking here though is that it may be nice to do the work outside of the codebase itself and instead allow plugins with something like lua which could allow users to do all sorts of weird and wonderful things like support LateX etc.

Do you have any preferences @henriklovhaug ?

image

henriklovhaug commented 3 months ago

I like the idea of a plugin ecosystem which make it easy to extend the program. Lua is a solid choice of course. I have had a bit of trouble with windows version building in CI/CD pipeline, but want to make it work there again. It broke with the introduction of tree-sitter. It's not a PR you wrote, but just a POC which looked good. Some part of temp file creation which need to be handled differently, but that's not important now.

I/we need to figure out how/where to allow for plugins to interoperate with the program. Naively would be with code blocks, but that won't work for LaTeX. Maybe allow a user to play with the syntax tree (or I would call it my ad hoc cluster) to transform it how one see fit. There are better Markdown parser out there to use if one need the syntax tree, so it would maybe be a bit annoying to work with this one.

If I want to settle on your POC method to just include mermaid I want it to be an active decision to opt in, paired with instructions for enabling.