This is actually something you can do quite easily in pandoc without any external tools, using the built-in lua filters.
Create run.lua:
--- run.lua
function CodeBlock(el)
if el.classes:includes("run") then
local prog = el.classes[1]
local result = pandoc.pipe(prog, {}, el.text)
return pandoc.RawBlock(FORMAT, result)
end
end
function Code(el)
if el.classes:includes("run") then
local prog = el.classes[1]
local result = pandoc.pipe(prog, {}, el.text):gsub('\n$','')
return pandoc.RawInline(FORMAT, result)
end
end
Now run
% cat > test.md
```{.python .run}
print("Hello from Python!")
print('$2^8 = {}$'.format(2**8))
```
Here's the date: `date`{.sh .run}.
^D
% pandoc --lua-filter run.lua -t markdown test.md
Hello from Python!
$2^8 = 256$
Here's the date: Thu Feb 28 09:52:21 PST 2019.
Note that the lua interpreter is built into pandoc, so you donβt need to install anything other than pandoc to use this.