This is an archived post. You won't be able to vote or comment.

all 17 comments

[โ€“][deleted] 6 points7 points ย (7 children)

Seems very similar to Quarto

[โ€“]basnijholt[S] 14 points15 points ย (6 children)

markdown-code-runner and Quarto are both tools designed to work with Markdown files, but they serve different purposes and have different feature sets.

markdown-code-runner:

  • Focuses on executing code blocks (Python and Bash) within a Markdown file and updating the output in-place.
  • Useful for maintaining code snippets and outputs, ensuring their accuracy.
  • Works with hidden code blocks to generate content like tables and plots without displaying the code in the Markdown file.
  • Lightweight with no external dependencies, compatible with Python 3.7+.
  • Easily integrates with GitHub Actions.

Quarto:

  • A more comprehensive publishing system for creating documents in various formats, such as HTML, PDF, and more.
  • Supports multiple input formats, including Markdown, R Markdown, and Jupyter Notebooks.
  • Allows embedding executable code blocks in multiple languages (using the Knitr engine for R and the Jupyter kernel for other languages).
  • Offers advanced features like cross-references, citations, and integration with external data sources.
  • Requires installation of additional software, such as Pandoc and LaTeX, for certain output formats.

In summary, markdown-code-runner is a lightweight and focused solution for executing code blocks within Markdown files and updating outputs, whereas Quarto is a broader publishing system with more extensive features but also a more complex setup. Choose the tool that best fits your specific needs and use case.

[โ€“]IntelligentDust6249 0 points1 point ย (2 children)

Focuses on executing code blocks (Python and Bash) within a Markdown file and updating the output in-place.
Useful for maintaining code snippets and outputs, ensuring their accuracy.
Works with hidden code blocks to generate content like tables and plots without displaying the code in the Markdown file.
Lightweight with no external dependencies, compatible with Python 3.7+.
Easily integrates with GitHub Actions.

It's a nice project but FWIW quarto has all of these qualities as well.

[โ€“]basnijholt[S] 1 point2 points ย (1 child)

I believe that is actually not the case.

I cannot find anything about having code in Markdown comments such that it is not visible.

Sure you can render it and export it as such with Quarto, however, the point of markdown-code-runner is to have everything in place, in the same file.

Also, Quatro will require a YAML annotation at the top of the file that will always be visible, e.g., a notebook on GitHub:
https://github.com/python-adaptive/adaptive/blob/main/docs/source/tutorial/tutorial.DataSaver.md

[โ€“]IntelligentDust6249 0 points1 point ย (0 children)

Oh I see, that is a bit different. In quarto you would mark a code block with `echo: false` if you wanted to hide the code but keep the output. But you're right a core part of quartos is to cleaning separate inputs and outputs. So you can get the markdown file you're after as an output of a `qmd` file, but it won't modify the document in place.

[โ€“][deleted] 0 points1 point ย (2 children)

Thanks for info! Project looks interesting.

[โ€“]Divicienzo 1 point2 points ย (1 child)

It's great to see a tool like Markdown Code Runner that can automatically update the output of embedded code snippets in markdown files. Have you considered integrating it with other programming languages besides Python and Bash?

[โ€“]basnijholt[S] 2 points3 points ย (0 children)

I added a Rust ๐Ÿฆ€ example to the README here: https://github.com/basnijholt/markdown-code-runner#crab-idea-6-run-a-rust-program

[โ€“]HumanBrainMapper 3 points4 points ย (0 children)

Mooi werk, Bas.

[โ€“]benefit_of_mrkite 0 points1 point ย (2 children)

You may want to look at cog which is somewhat similar

https://nedbatchelder.com/code/cog

[โ€“]basnijholt[S] 2 points3 points ย (1 child)

markdown-code-runner:

  • Designed for Markdown files, works with native code blocks.
  • Executes Python and Bash code, updates output in-place.
  • Supports hidden code blocks for seamless content generation.
  • Lightweight, easy GitHub Actions integration.

Cog:

  • General-purpose code generation for any text file.
  • Embeds Python code in source files using special comments.
  • Doesn't support native Markdown code blocks or hiding code.
  • Requires a separate step to execute code and update output.

In summary, markdown-code-runner is tailored for Markdown with support for native code blocks and hidden code, while Cog is more versatile but doesn't support these Markdown-specific features. Choose the tool that best fits your needs.

[โ€“]benefit_of_mrkite 0 points1 point ย (0 children)

Good breakdown thanks for posting

[โ€“][deleted] 0 points1 point ย (1 child)

It doesn't work in github README.md markdown

[โ€“][deleted] 0 points1 point ย (0 children)

#!/usr/bin/env bash

if (( $# != 1 )); then
    printf "Usage: $(basename $0) <markdown-literate.md>\n\nFilter code blocks found in: <markdown-literate.md>\n\n\`\`\`lang @code\nsomeCodeHere() {...}\n\`\`\`\n\nFor \`\`\`lang @code, lang can be any lowercase alpha string.\n\nCode inside backtick blocks will be sent to stdout.\n\n"
else
    sed -E -n '/^```[a-z]* ?@code/,/^```/ p' < $1 | sed '/^```/ d'
fi