Include Code Samples Files
Your files:
include-code-block.lua
docs/
my-file.md
code-samples/
Foo.hx
In my-file.md:
Hi.
~~~{.haxe include=code-samples/Foo.hx}
~~~
Bye.
In include-code-block.lua:
function CodeBlock (cb)
if cb.attributes.include then
-- read file
local fh = io.open(cb.attributes.include)
local content = fh:read('*a')
:close()
fh-- remove key-value pair for key "include"
.attributes.include = nil
cb-- return final code block
return pandoc.CodeBlock(content, cb.attr)
end
end
Then, from within the docs directory, process like so:
pandoc -s -o my-file.html --lua-filter=../include-code-block.lua my-file.md