run code-blocks in markdown files and insert the results immediately below, like a home-brewed jupyter notebook.
- basic functionality
- additional languages
- matplotlib support (TODO)
Either
1. execute with ./execute_md.py [SOURCE] [DEST]
or ./execute_md.py [SOURCE]
(which will print results to stdout), or
2. use it through python (or whatever you want to FFI that to)
from execute_md import execute_md open('dest.md', 'w').writelines(execute_md(open('src.md', 'r')))
This'll be ignored
The following block starts with
'''python#run
def f(x):
if x <= 1: return 1
return x * f(x-1)
print([f(x) for x in range(6)])
The #run
tag is stripped from the final output, leaving us with just a codeblock starting with '''python
, followed by a second codeblock with output.
Again, just done with '''python#run
.
print(f(10))
This one uses one additional tag, now looking like '''python#run#new
. Snazzy.
print(f(11))
'''python#run#unboxed
print('This is a test of *various* **markdown** ~~features~~.')
Hidden input-field with #hide
The source code block here looks like the following:
'''python#run#hide print(1+2) '''
However that gets dropped from the file, leaving us with just
print(1+2)
This one uses '''python#run#output_first
:
print(3+4)
infix = ', of course,'
print(f"These tags can{infix} be combined. Just look at this very sentence in [README_src.md](https://raw.githubusercontent.com/FraserLee/execute-dot-md/main/README_src.md) 😉")
!req(languages/rust_example1.rs)
!req(languages/rust_example2.rs)
print(2+2)
!req(languages/c_example.c)
!req(languages/cpp_example.cpp)
!req(languages/bash_example.sh)
!req(languages/go_example.go)
!req(languages/js_example.js)
!req(languages/lua_example.lua)
!req(languages/kotlin_example.kts)
main = (putStrLn . reverse) "!dlrow olleh"
proc factorial(x: int): int =
if x <= 0: 1
else: x * factorial(x - 1)
echo "10! = ", factorial(10)
class Main {
static public function main() {
trace("hello world");
}
}
print_string "hello world\n"
class Main{
public static void main(String[] args){
System.out.println("hello world!");
}
}
echo "hello world!"
(example sourced from Wikipedia)
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>
---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.