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 comments
luckman212 10/26/2024|
For Obsidian users, I'm a fan of the Execute Code[0] plugin which allows exexution of codeblocks straight from your notes.

[0]: https://github.com/twibiral/obsidian-execute-code

luckman212 10/26/2024|
I spelled 'execution' wrong. Ugh. Careful running those codeblocks :)
dingnuts 10/26/2024||
ah, someone has reimplemented another feature of Org Mode.

Well, this will mean Org files exported to Markdown can remain executable just like they were in Emacs, so maybe this makes Org Babel more valuable as well, for those of us that prefer a structured markup language for notes and literate programming

And thanks to pandoc it's not hard to go back and forth

oezi 10/26/2024||
Are you referring to this?

https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-...

dingnuts 10/26/2024|||
Yes, the feature is called org-babel and it lets you write and execute polyglot literate programs.
alwayslikethis 10/26/2024|||
org babel supports way more languages. Elisp (obviously), python, C, C++, Java, you name it
Bromeo 10/26/2024|||
Yup, looks like org-babel is at least 15 years old. https://github.com/taruti/org-babel/tree/master

I don't think it ever had huge adoption across whole teams, but I hope if there are new implementations that they take away a number of lessons you can gather from 15 years of org-babel.

VyseofArcadia 10/26/2024|||
Those who do not understand Emacs are doomed to reinvent it, poorly.

With apologies to Henry Spencer.

oezi 10/26/2024||
Casting off the shackles of Lisp! There are worse mistakes.
bluesnews 10/26/2024||
This idea isn't just from one source but that doesn't mean another implementation isn't worthy.

We did similar at a company I worked for 15 yrs ago

Serenacula 10/28/2024||
I would put forward that mdx is not a great choice of name, given that it already has a standard meaning in the markdown ecosystem: markdown with inline react components.
oezi 10/26/2024||
Similar in Ruby/shameless pluck:

https://github.com/coezbek/baker

I call this a Project-Setup-as-Code tool.

Supports backticks for shell and triple backticks for executing Ruby code.

If blocks are successfully executed they are marked as done (using markdown [x] checkboxes). So you can incrementally run a file without executing stuff twice.

Galanwe 10/26/2024||
Cool, at last we can now `curl | mdx` Github readmes instead of copy pasting `curl | bash` from them!
aziis98 10/26/2024||
Note: If one writes a cell with "you can install this with `curl | mdx`" this ends up in an infinite loop xD.
lioeters 10/26/2024||
That's both exhilarating and terrifying at the same time. Please don't tempt me. At least it's better than:

  chatgpt -m "I'm feeling lucky" | sudo bash
drunken_thor 10/26/2024||
This is a great tool for writing technical documentation sites. It will allow you to run tests on your code samples, ensuring that they are up to date and working with the most recent library release. We were in progress of doing this with Shopify.dev before I left.
theK 10/26/2024||
Cool idea. Stuff like this reminds me why I like the vim ecosystem so much. At least since the introduction of terminal buffers, most people I know that use vim for serious code work have a form of "send text under cursor to shell"
dingnuts 10/26/2024|
Helix and Emacs have that built in by the way
mdaniel 10/27/2024||
> Emacs have that built in by the way

Org mode is stellar at that "code in document" tangling, but I'll be honest that I loathe the M-| behavior in emacs since, unlike its vim friend, it puts the output in a separate buffer, placing the burden upon me to copy/cut it back into the source buffer

karthink 10/27/2024|||
You can add a prefix arg to replace the region with the result. (Any numeric prefix works, so I usually do M-0 M-| since that's easy to type with the meta key held down, and 0 and | are close together.)
alexflpf 10/27/2024|||
Just add a prefix arg to replace the region you run it on: C-u M-|
josephbergevin 10/28/2024||
I started in on a similar project a few months ago when I was going through a short "burn out" phase, haha.

https://github.com/josephbergevin/codebook-md

Have a look, I'd love to get some feedback. For me, it's in a good enough state that I'm able to use it in my everyday coding - but it definitely has a lot of room for improvement.

admc 10/26/2024||
I'd like to commend you on building something and putting it out in there in the world, keep doing that! Also the idea of running commands and code from Markdown is obviously awesome. I think you'll find that the folks you get to use this will want a ton more features, like project wide config, interactive stdin, .ENV tooling, passing of variables between inputs and a lot more. That's why we built runme.dev, the kernel is built in Go, please come join our community and contribute.
dim0x69 10/27/2024|
I did not know runme.dev. Thanks for reaching out! It looks absolutely awesome
kitd 10/26/2024|
Congratulations! Nice work.

If you like this, another similar tool, though one specifically geared towards builds, is xc.

https://xcfile.dev/

More comments...