Top
Best
New

Posted by dim0x69 10/26/2024

Show HN: Mdx – Execute your Markdown code blocks, now in Go(github.com)
Hey HN! I recently came across makedown here on HN and loved the concept. Wanting to learn Go, I thought this could be a great starter project - so I started working on my own Go implementation, which I’m calling mdx (https://github.com/dim0x69/mdx).

Key Features:

- Define dependencies between commands

- Supports shebangs

- Ability to pass arguments to code blocks

Would love feedback and thoughts!

Ref. makedown: https://github.com/tzador/makedown. Thanks for the idea! :)

127 points | 56 commentspage 2
eterps 10/26/2024|
Could use some more (or better?) examples of how this can be useful.
codetrotter 10/26/2024||
I do something similar.

In some of my projects I have little snippets of cli commands in the main README.

When I open the project in JetBrains IDE and I open the README of my project there, I can click on each code block to run it.

This way I can for example start up dependencies like say a little python3 web server to serve static files from one of the subdirs, simply by clicking on it in the readme. Instead of copy-pasting from the readme, and even instead of Ctrl+R in a terminal window and finding the correct commands for a project from history.

It almost reminds me a little bit of Plan9 and their Acme editor, where they were blurring the lines between text and commands. In Acme you can type a piece of text and then middle-button click I think it was to run the text as a command. Having executable blocks of code interspersed in a markdown document feels a little bit like that although in a different, more limited manner.

codetrotter 10/26/2024||
Also to add, for a while in the past before I found that the IDE I use could execute code blocks I made a little program that would take each code block in a markdown document and run them one after the other, and it would look to see if a “text” fence followed right after the code fence. In that case it would write the output of that command into the text fence. If there was no text fence, it would run the command without inserting any of its input into the document.

It was like a super rudimentary Jupyter Notebook system of my own making.

Eventually I switched away from my own run-and-insert system.

sourishkrout 10/27/2024||
This Jupyter notebook-like system you're describing here is basically Runme. It do not yet have an IntelliJ/Jetbrains plugin; however, the Kernel Architecture outside of the headless CLI allows for integration into any IDE or UI.

It's all open source. Please get involved! We'd be happy to have you.

glyphacki 10/26/2024||
I can think of code examples in the documentation. At least you make sure the code is executed or even check the output of the examples.
DJBunnies 10/26/2024||
If only we had a mechanism for demonstrating correct and incorrect ways to use a particular software.

We could expect failure conditions or assert correct outcomes.

It could become a little library of examples that change over time, as the software changes, granting us peace of mind that everything still works.

pomdtr 10/26/2024||
I would prefer an api base on codeblocks meta string and json attributes.

```sh name="build" deps=["install"]

npm run build

```

This would be displayed just fine in github, as it is valid gfm.

mdaniel 10/27/2024|
RunMe[1] seems like it is what you're looking for: https://docs.runme.dev/usage/run-tag

1: https://github.com/stateful/runme#runme-runs-markdown-- (Apache 2, golang)

I wondered why Runme wasn't already mentioned but it seems the comment got nested under a dead thread https://news.ycombinator.com/item?id=41955834

oezi 10/26/2024||
Can you compare to https://github.com/bashup/mdsh ?
lagniappe 10/26/2024||
This is really cool, I was just thinking recently about something like that. What do you plan to add to it next? What do you think of Go?
huac 10/26/2024||
reminds me a lot of rmarkdown - which allows you to run many languages in a similar fashion https://rmarkdown.rstudio.com/
starkparker 10/26/2024||
cf. rundown https://github.com/elseano/rundown
kchr 10/27/2024|
I need a rundown of your clients.
wdavidw 10/26/2024||
It is similar to how CoffeeScript literate works.
javajosh 10/26/2024||
I wrote something similar, but for the web. I call it "Literate Markdown" (https://simpatico.io/lit.md) and you write markdown and your html/css/js/md code blocks are both exposed as text and as code blocks for execution in the browser. The format expects to a) be transformed and exposed by a special server (https://simpatico.io/reflector.md) and b) rendered in a browser. This code also includes a simple test harness that, for example, turns the favicon green/red depending on if exceptions are thrown in your code (https://simpatico.io/testable.js) I also wrote an acceptance test that loads most of the interesting parts of the site in iframes and combines their test output (https://simpatico.io/acceptance). That page also has notes for using headless chrome to run the tests. Also, the server (lazily) caches all transforms with file watcher invalidation, disallows 3rd party cookies, and starts up instantly.

The central use case is to have a fun and fast way to play with browser code, using your favorite editor, and literate programming techniques. All while being open source, local first, and minimalist.

The repo (https://github.com/javajosh/simpatico/) is not yet npm/npx compatible so you have to fork and run. This is a local first, minimalist project that has ~2 small dependencies, which themselves have no deps, so publishing was not a priority.

Eventually I'd like to automate an md-> js process, such that the md is the canonical source for javascript and the final js is a build product. I'd also like to clean up the code and publish to npm, but sadly someone is squatting on the @simpatico handle and npm won't do anything. :(

jpillora 10/26/2024||
See also https://github.com/jpillora/md-tmpl
nicoburns 10/26/2024|
You might want to reconsider the name. MDX is already a well-known technology that combines markdown with JSX https://github.com/mdx-js/mdx/
jrajav 10/26/2024||
It also sees very wide use, it's not just a proof of concept - most who've used any recent major version of Storybook (84k stars) would know about it: https://storybook.js.org/docs/writing-docs/mdx
ValentineC 10/26/2024||
Not just Storybook, but most modern JavaScript-based static site generators, for example:

- Astro: https://docs.astro.build/en/guides/integrations-guide/mdx/

- Docusaurus: https://docusaurus.io/docs/markdown-features/react

- Eleventy: https://www.11ty.dev/docs/languages/mdx/

- NextJS: https://nextjs.org/docs/pages/building-your-application/conf...

dcmatt 10/26/2024|||
Also Multidimensional expressions, popular in OLAP cubes. https://en.wikipedia.org/wiki/MultiDimensional_eXpressions
lsaferite 10/27/2024|||
I came to make the same comment, so glad it's been brought up and reenforced.

https://mdxjs.com/

zoover2020 10/26/2024|||
Came here to say this, confusion ensued.
edsammy 10/26/2024||
marko or godown would be fun
no_wizard 10/26/2024||
Marko too is taken https://markojs.com/
More comments...